Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | #include "internal.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <errno.h> |
| 6 | |
Pavel Roskin | 9c5fcc3 | 2000-07-17 23:45:12 +0000 | [diff] [blame^] | 7 | #define bb_need_full_version |
| 8 | #define BB_DECLARE_EXTERN |
| 9 | #include "messages.c" |
| 10 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 11 | static int been_there_done_that = 0; |
| 12 | |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 13 | /* It has been alledged that doing such things can |
| 14 | * help reduce binary size when staticly linking, |
| 15 | * of course with glibc, this is unlikely as long |
| 16 | * as we use things like printf -- perhaps a printf |
| 17 | * replacement may be in order |
| 18 | */ |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 19 | #if 0 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 20 | void exit(int status) __attribute__ ((noreturn)); |
| 21 | void exit(int status) |
| 22 | { |
| 23 | _exit(status); |
| 24 | }; |
| 25 | void abort(void) __attribute__ ((__noreturn__)); |
| 26 | void abort(void) |
| 27 | { |
| 28 | _exit(0); |
| 29 | }; |
| 30 | int atexit(void (*__func) (void)) |
| 31 | { |
| 32 | _exit(0); |
| 33 | }; |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 34 | void *__libc_stack_end; |
| 35 | #endif |
| 36 | |
Erik Andersen | bcd6177 | 2000-05-13 06:33:19 +0000 | [diff] [blame] | 37 | const struct BB_applet applets[] = { |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 38 | |
Eric Andersen | 86ab8a3 | 2000-06-02 03:21:42 +0000 | [diff] [blame] | 39 | #ifdef BB_AR |
| 40 | {"ar", ar_main, _BB_DIR_USR_BIN}, |
| 41 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 42 | #ifdef BB_BASENAME |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 43 | {"basename", basename_main, _BB_DIR_USR_BIN}, |
Erik Andersen | e272915 | 2000-02-18 21:34:17 +0000 | [diff] [blame] | 44 | #endif |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 45 | {"busybox", busybox_main, _BB_DIR_BIN}, |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 46 | #ifdef BB_CAT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 47 | {"cat", cat_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 48 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 49 | #ifdef BB_CHMOD_CHOWN_CHGRP |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 50 | {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN}, |
| 51 | #endif |
| 52 | #ifdef BB_CHMOD_CHOWN_CHGRP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 53 | {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN}, |
| 54 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 55 | #ifdef BB_CHMOD_CHOWN_CHGRP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 56 | {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN}, |
| 57 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 58 | #ifdef BB_CHROOT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 59 | {"chroot", chroot_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 60 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 61 | #ifdef BB_CLEAR |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 62 | {"clear", clear_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 63 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 64 | #ifdef BB_CHVT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 65 | {"chvt", chvt_main, _BB_DIR_USR_BIN}, |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 66 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 67 | #ifdef BB_CP_MV |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 68 | {"cp", cp_mv_main, _BB_DIR_BIN}, |
| 69 | #endif |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 70 | #ifdef BB_CUT |
| 71 | {"cut", cut_main, _BB_DIR_USR_BIN}, |
| 72 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 73 | #ifdef BB_DATE |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 74 | {"date", date_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 75 | #endif |
John Beppu | 0021679 | 2000-06-21 19:06:16 +0000 | [diff] [blame] | 76 | #ifdef BB_DC |
| 77 | {"dc", dc_main, _BB_DIR_USR_BIN}, |
| 78 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 79 | #ifdef BB_DD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 80 | {"dd", dd_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 81 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 82 | #ifdef BB_DF |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 83 | {"df", df_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 84 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 85 | #ifdef BB_DIRNAME |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 86 | {"dirname", dirname_main, _BB_DIR_USR_BIN}, |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 87 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 88 | #ifdef BB_DMESG |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 89 | {"dmesg", dmesg_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 90 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 91 | #ifdef BB_DU |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 92 | {"du", du_main, _BB_DIR_BIN}, |
John Beppu | 7a98606 | 1999-12-09 18:29:29 +0000 | [diff] [blame] | 93 | #endif |
Eric Andersen | 61dc057 | 2000-07-11 17:29:36 +0000 | [diff] [blame] | 94 | #ifdef BB_DUMPKMAP |
| 95 | {"dumpkmap", dumpkmap_main, _BB_DIR_BIN}, |
| 96 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 97 | #ifdef BB_DUTMP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 98 | {"dutmp", dutmp_main, _BB_DIR_USR_SBIN}, |
| 99 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 100 | #ifdef BB_ECHO |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 101 | {"echo", echo_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 102 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 103 | #ifdef BB_TRUE_FALSE |
| 104 | {"false", false_main, _BB_DIR_BIN}, |
| 105 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 106 | #ifdef BB_FBSET |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 107 | {"fbset", fbset_main, _BB_DIR_USR_SBIN}, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 108 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 109 | #ifdef BB_FDFLUSH |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 110 | {"fdflush", fdflush_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 111 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 112 | #ifdef BB_FIND |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 113 | {"find", find_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 115 | #ifdef BB_FREE |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 116 | {"free", free_main, _BB_DIR_USR_BIN}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 117 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 118 | #ifdef BB_FREERAMDISK |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 119 | {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN}, |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 120 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 121 | #ifdef BB_DEALLOCVT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 122 | {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 123 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 124 | #ifdef BB_FSCK_MINIX |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 125 | {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN}, |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 126 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 127 | #ifdef BB_GREP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 128 | {"grep", grep_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 129 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 130 | #ifdef BB_GUNZIP |
| 131 | {"gunzip", gunzip_main, _BB_DIR_BIN}, |
| 132 | #endif |
| 133 | #ifdef BB_GZIP |
| 134 | {"gzip", gzip_main, _BB_DIR_BIN}, |
| 135 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 136 | #ifdef BB_HALT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 137 | {"halt", halt_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 138 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 139 | #ifdef BB_HEAD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 140 | {"head", head_main, _BB_DIR_BIN}, |
John Beppu | 3157b1f | 1999-12-10 07:42:50 +0000 | [diff] [blame] | 141 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 142 | #ifdef BB_HOSTID |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 143 | {"hostid", hostid_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 144 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 145 | #ifdef BB_HOSTNAME |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 146 | {"hostname", hostname_main, _BB_DIR_BIN}, |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 147 | #endif |
Erik Andersen | 94f5e0b | 2000-05-01 19:10:52 +0000 | [diff] [blame] | 148 | #ifdef BB_ID |
| 149 | {"id", id_main, _BB_DIR_USR_BIN}, |
| 150 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 151 | #ifdef BB_INIT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 152 | {"init", init_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 153 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 154 | #ifdef BB_INSMOD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 155 | {"insmod", insmod_main, _BB_DIR_SBIN}, |
Erik Andersen | 6da0ae8 | 1999-12-17 01:08:27 +0000 | [diff] [blame] | 156 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 157 | #ifdef BB_KILL |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 158 | {"kill", kill_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 159 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 160 | #ifdef BB_KILLALL |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 161 | {"killall", kill_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 246cc6d | 2000-03-07 07:41:42 +0000 | [diff] [blame] | 162 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 163 | #ifdef BB_LENGTH |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 164 | {"length", length_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 165 | #endif |
Erik Andersen | 9a8195c | 2000-04-18 23:32:10 +0000 | [diff] [blame] | 166 | #ifdef BB_LINUXRC |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 167 | {"linuxrc", init_main, _BB_DIR_ROOT}, |
| 168 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 169 | #ifdef BB_LN |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 170 | {"ln", ln_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 171 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 172 | #ifdef BB_LOADACM |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 173 | {"loadacm", loadacm_main, _BB_DIR_USR_BIN}, |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 174 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 175 | #ifdef BB_LOADFONT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 176 | {"loadfont", loadfont_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 177 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 178 | #ifdef BB_LOADKMAP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 179 | {"loadkmap", loadkmap_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 180 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 181 | #ifdef BB_LOGGER |
| 182 | {"logger", logger_main, _BB_DIR_USR_BIN}, |
| 183 | #endif |
| 184 | #ifdef BB_LOGNAME |
| 185 | {"logname", logname_main, _BB_DIR_USR_BIN}, |
| 186 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 187 | #ifdef BB_LS |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 188 | {"ls", ls_main, _BB_DIR_BIN}, |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 189 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 190 | #ifdef BB_LSMOD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 191 | {"lsmod", lsmod_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 192 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 193 | #ifdef BB_MAKEDEVS |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 194 | {"makedevs", makedevs_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 195 | #endif |
Eric Andersen | 2b6ab3c | 2000-06-13 06:54:53 +0000 | [diff] [blame] | 196 | #ifdef BB_MD5SUM |
| 197 | {"md5sum", md5sum_main, _BB_DIR_USR_BIN}, |
| 198 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 199 | #ifdef BB_MKDIR |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 200 | {"mkdir", mkdir_main, _BB_DIR_BIN}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 201 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 202 | #ifdef BB_MKFIFO |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 203 | {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN}, |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 204 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 205 | #ifdef BB_MKFS_MINIX |
| 206 | {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN}, |
| 207 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 208 | #ifdef BB_MKNOD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 209 | {"mknod", mknod_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 210 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 211 | #ifdef BB_MKSWAP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 212 | {"mkswap", mkswap_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 213 | #endif |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 214 | #ifdef BB_MKTEMP |
| 215 | {"mktemp", mktemp_main, _BB_DIR_BIN}, |
| 216 | #endif |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 217 | #ifdef BB_NC |
| 218 | {"nc", nc_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 219 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 220 | #ifdef BB_MORE |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 221 | {"more", more_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 222 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 223 | #ifdef BB_MOUNT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 224 | {"mount", mount_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 225 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 226 | #ifdef BB_MT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 227 | {"mt", mt_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 228 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 229 | #ifdef BB_CP_MV |
| 230 | {"mv", cp_mv_main, _BB_DIR_BIN}, |
| 231 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 232 | #ifdef BB_NSLOOKUP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 233 | {"nslookup", nslookup_main, _BB_DIR_USR_BIN}, |
John Beppu | b332e77 | 2000-01-29 12:59:01 +0000 | [diff] [blame] | 234 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 235 | #ifdef BB_PING |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 236 | {"ping", ping_main, _BB_DIR_BIN}, |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 237 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 238 | #ifdef BB_POWEROFF |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 239 | {"poweroff", poweroff_main, _BB_DIR_SBIN}, |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 240 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 241 | #ifdef BB_PRINTF |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 242 | {"printf", printf_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 243 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 244 | #ifdef BB_PS |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 245 | {"ps", ps_main, _BB_DIR_BIN}, |
Eric Andersen | ef8b6c7 | 1999-10-20 08:05:35 +0000 | [diff] [blame] | 246 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 247 | #ifdef BB_PWD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 248 | {"pwd", pwd_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 249 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 250 | #ifdef BB_REBOOT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 251 | {"reboot", reboot_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 252 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 253 | #ifdef BB_RM |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 254 | {"rm", rm_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 255 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 256 | #ifdef BB_RMDIR |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 257 | {"rmdir", rmdir_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 258 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 259 | #ifdef BB_RMMOD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 260 | {"rmmod", rmmod_main, _BB_DIR_SBIN}, |
Erik Andersen | 3d7e341 | 1999-12-16 23:04:20 +0000 | [diff] [blame] | 261 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 262 | #ifdef BB_SED |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 263 | {"sed", sed_main, _BB_DIR_BIN}, |
Erik Andersen | 3522eb1 | 2000-03-12 23:49:18 +0000 | [diff] [blame] | 264 | #endif |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 265 | #ifdef BB_SETKEYCODES |
| 266 | {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 3522eb1 | 2000-03-12 23:49:18 +0000 | [diff] [blame] | 267 | #endif |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 268 | #ifdef BB_SH |
| 269 | {"sh", shell_main, _BB_DIR_BIN}, |
| 270 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 271 | #ifdef BB_SLEEP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 272 | {"sleep", sleep_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 273 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 274 | #ifdef BB_SORT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 275 | {"sort", sort_main, _BB_DIR_BIN}, |
John Beppu | 019513a | 1999-12-22 17:57:31 +0000 | [diff] [blame] | 276 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 277 | #ifdef BB_SYNC |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 278 | {"sync", sync_main, _BB_DIR_BIN}, |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 279 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 280 | #ifdef BB_SYSLOGD |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 281 | {"syslogd", syslogd_main, _BB_DIR_SBIN}, |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 282 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 283 | #ifdef BB_SWAPONOFF |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 284 | {"swapon", swap_on_off_main, _BB_DIR_SBIN}, |
| 285 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 286 | #ifdef BB_SWAPONOFF |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 287 | {"swapoff", swap_on_off_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 288 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 289 | #ifdef BB_TAIL |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 290 | {"tail", tail_main, _BB_DIR_USR_BIN}, |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 291 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 292 | #ifdef BB_TAR |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 293 | {"tar", tar_main, _BB_DIR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 294 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 295 | #ifdef BB_TELNET |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 296 | {"telnet", telnet_main, _BB_DIR_USR_BIN}, |
| 297 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 298 | #ifdef BB_TEST |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 299 | {"test", test_main, _BB_DIR_USR_BIN}, |
Erik Andersen | f7c49ef | 2000-02-22 17:17:45 +0000 | [diff] [blame] | 300 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 301 | #ifdef BB_TEE |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 302 | {"tee", tee_main, _BB_DIR_BIN}, |
John Beppu | 059f152 | 1999-12-10 05:27:16 +0000 | [diff] [blame] | 303 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 304 | #ifdef BB_TOUCH |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 305 | {"touch", touch_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 306 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 307 | #ifdef BB_TR |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 308 | {"tr", tr_main, _BB_DIR_USR_BIN}, |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 309 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 310 | #ifdef BB_TRUE_FALSE |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 311 | {"true", true_main, _BB_DIR_BIN}, |
| 312 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 313 | #ifdef BB_TTY |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 314 | {"tty", tty_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 315 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 316 | #ifdef BB_UMOUNT |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 317 | {"umount", umount_main, _BB_DIR_BIN}, |
Erik Andersen | 66be5e7 | 2000-03-05 07:52:05 +0000 | [diff] [blame] | 318 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 319 | #ifdef BB_UNAME |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 320 | {"uname", uname_main, _BB_DIR_BIN}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 321 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 322 | #ifdef BB_UNIQ |
Erik Andersen | a6c7522 | 2000-04-18 00:00:52 +0000 | [diff] [blame] | 323 | {"uniq", uniq_main, _BB_DIR_USR_BIN}, |
John Beppu | abb4772 | 2000-01-06 00:48:21 +0000 | [diff] [blame] | 324 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 325 | #ifdef BB_UPDATE |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 326 | {"update", update_main, _BB_DIR_SBIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 327 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 328 | #ifdef BB_UPTIME |
| 329 | {"uptime", uptime_main, _BB_DIR_USR_BIN}, |
| 330 | #endif |
Eric Andersen | 2b6ab3c | 2000-06-13 06:54:53 +0000 | [diff] [blame] | 331 | #ifdef BB_UUENCODE |
| 332 | {"uuencode", uuencode_main, _BB_DIR_USR_BIN}, |
| 333 | #endif |
| 334 | #ifdef BB_UUDECODE |
| 335 | {"uudecode", uudecode_main, _BB_DIR_USR_BIN}, |
| 336 | #endif |
Erik Andersen | b99ca13 | 2000-04-04 18:49:18 +0000 | [diff] [blame] | 337 | #ifdef BB_USLEEP |
| 338 | {"usleep", usleep_main, _BB_DIR_BIN}, |
| 339 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 340 | #ifdef BB_WC |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 341 | {"wc", wc_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 342 | #endif |
Erik Andersen | 330fd2b | 2000-05-19 05:35:19 +0000 | [diff] [blame] | 343 | #ifdef BB_WHICH |
| 344 | {"which", which_main, _BB_DIR_USR_BIN}, |
| 345 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 346 | #ifdef BB_WHOAMI |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 347 | {"whoami", whoami_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 348 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 349 | #ifdef BB_YES |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 350 | {"yes", yes_main, _BB_DIR_USR_BIN}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 351 | #endif |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 352 | #ifdef BB_GUNZIP |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 353 | {"zcat", gunzip_main, _BB_DIR_BIN}, |
| 354 | #endif |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 355 | #ifdef BB_TEST |
| 356 | {"[", test_main, _BB_DIR_USR_BIN}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 357 | #endif |
Eric Andersen | d6912c9 | 2000-07-14 06:29:10 +0000 | [diff] [blame] | 358 | {0,NULL,0} |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 359 | }; |
| 360 | |
Matt Kraai | 3ecbe9f | 2000-07-12 00:43:28 +0000 | [diff] [blame] | 361 | char *applet_name; |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 362 | |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 363 | #ifdef BB_FEATURE_INSTALLER |
| 364 | /* |
| 365 | * directory table |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 366 | * this should be consistent w/ the enum, internal.h::Location, |
| 367 | * or else... |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 368 | */ |
| 369 | static char* install_dir[] = { |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 370 | "/", |
| 371 | "/bin", |
| 372 | "/sbin", |
| 373 | "/usr/bin", |
| 374 | "/usr/sbin", |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | /* abstract link() */ |
| 378 | typedef int (*__link_f)(const char *, const char *); |
| 379 | |
John Beppu | 7cdc76d | 2000-06-28 00:41:26 +0000 | [diff] [blame] | 380 | /* |
| 381 | * Where in the filesystem is this busybox? |
| 382 | * [return] |
| 383 | * malloc'd string w/ full pathname of busybox's location |
| 384 | * NULL on failure |
| 385 | */ |
| 386 | static char *busybox_fullpath() |
| 387 | { |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 388 | pid_t pid; |
| 389 | char path[256]; |
| 390 | char proc[256]; |
| 391 | int len; |
John Beppu | 7cdc76d | 2000-06-28 00:41:26 +0000 | [diff] [blame] | 392 | |
| 393 | pid = getpid(); |
| 394 | sprintf(proc, "/proc/%d/exe", pid); |
| 395 | len = readlink(proc, path, 256); |
| 396 | if (len != -1) { |
| 397 | path[len] = 0; |
| 398 | } else { |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 399 | errorMsg("%s: %s\n", proc, strerror(errno)); |
John Beppu | 7cdc76d | 2000-06-28 00:41:26 +0000 | [diff] [blame] | 400 | return NULL; |
| 401 | } |
| 402 | return strdup(path); |
| 403 | } |
| 404 | |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 405 | /* create (sym)links for each applet */ |
John Beppu | 495869f | 2000-06-27 07:54:33 +0000 | [diff] [blame] | 406 | static int install_links(const char *busybox, int use_symbolic_links) |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 407 | { |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 408 | __link_f Link = link; |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 409 | |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 410 | char command[256]; |
| 411 | int i; |
| 412 | int rc = 0; |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 413 | |
| 414 | if (use_symbolic_links) Link = symlink; |
| 415 | |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 416 | for (i = 0; applets[i].name != NULL; i++) { |
| 417 | sprintf ( |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 418 | command, |
| 419 | "%s/%s", |
| 420 | install_dir[applets[i].location], |
| 421 | applets[i].name |
| 422 | ); |
John Beppu | 7cdc76d | 2000-06-28 00:41:26 +0000 | [diff] [blame] | 423 | #if 1 |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 424 | rc |= Link(busybox, command); |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 425 | #else |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 426 | puts(command); |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 427 | #endif |
| 428 | if (rc) { |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 429 | errorMsg("%s: %s\n", command, strerror(errno)); |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 430 | } |
John Beppu | eb02833 | 2000-06-28 00:55:31 +0000 | [diff] [blame] | 431 | } |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 432 | return rc; |
| 433 | } |
| 434 | |
| 435 | #if 0 |
| 436 | int uninstall_links() ? |
| 437 | #endif |
| 438 | #endif /* BB_FEATURE_INSTALLER */ |
| 439 | |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 440 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 441 | int main(int argc, char **argv) |
| 442 | { |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 443 | char *s; |
Erik Andersen | bcd6177 | 2000-05-13 06:33:19 +0000 | [diff] [blame] | 444 | const struct BB_applet *a = applets; |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 445 | applet_name = "busybox"; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 446 | |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 447 | #ifdef BB_FEATURE_INSTALLER |
John Beppu | 27b5924 | 2000-06-27 04:56:45 +0000 | [diff] [blame] | 448 | /* |
| 449 | * This style of argument parsing doesn't scale well |
| 450 | * in the event that busybox starts wanting more --options. |
| 451 | * If someone has a cleaner approach, by all means implement it. |
| 452 | */ |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 453 | if (argc > 1 && (strcmp(argv[1], "--install") == 0)) { |
| 454 | int use_symbolic_links = 0; |
John Beppu | 7cdc76d | 2000-06-28 00:41:26 +0000 | [diff] [blame] | 455 | int rc = 0; |
| 456 | char *busybox; |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 457 | |
John Beppu | 27b5924 | 2000-06-27 04:56:45 +0000 | [diff] [blame] | 458 | /* to use symlinks, or not to use symlinks... */ |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 459 | if (argc > 2) { |
| 460 | if ((strcmp(argv[2], "-s") == 0)) { |
| 461 | use_symbolic_links = 1; |
| 462 | } |
| 463 | } |
John Beppu | 7cdc76d | 2000-06-28 00:41:26 +0000 | [diff] [blame] | 464 | |
| 465 | /* link */ |
| 466 | busybox = busybox_fullpath(); |
| 467 | if (busybox) { |
| 468 | install_links(busybox, use_symbolic_links); |
| 469 | free(busybox); |
| 470 | } else { |
| 471 | rc = 1; |
| 472 | } |
| 473 | return rc; |
John Beppu | 8f425db | 2000-06-27 04:50:02 +0000 | [diff] [blame] | 474 | } |
| 475 | #endif /* BB_FEATURE_INSTALLER */ |
| 476 | |
Matt Kraai | 7719008 | 2000-07-11 20:03:24 +0000 | [diff] [blame] | 477 | for (s = applet_name = argv[0]; *s != '\0';) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 478 | if (*s++ == '/') |
Matt Kraai | 7719008 | 2000-07-11 20:03:24 +0000 | [diff] [blame] | 479 | applet_name = s; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 480 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 481 | |
Matt Kraai | 7719008 | 2000-07-11 20:03:24 +0000 | [diff] [blame] | 482 | *argv = applet_name; |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 483 | |
Eric Andersen | 5d41d60 | 2000-06-29 20:20:14 +0000 | [diff] [blame] | 484 | #ifdef BB_SH |
| 485 | /* Add in a special case hack -- whenever **argv == '-' |
| 486 | * (i.e. '-su' or '-sh') always invoke the shell */ |
| 487 | if (**argv == '-') |
| 488 | exit(((*(shell_main)) (argc, argv))); |
| 489 | #endif |
| 490 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 491 | while (a->name != 0) { |
Matt Kraai | 7719008 | 2000-07-11 20:03:24 +0000 | [diff] [blame] | 492 | if (strcmp(applet_name, a->name) == 0) { |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 493 | exit(((*(a->main)) (argc, argv))); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 494 | } |
| 495 | a++; |
| 496 | } |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 497 | return(busybox_main(argc, argv)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | |
| 501 | int busybox_main(int argc, char **argv) |
| 502 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 503 | int col = 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 504 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 505 | argc--; |
| 506 | argv++; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 507 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 508 | if (been_there_done_that == 1 || argc < 1) { |
Erik Andersen | bcd6177 | 2000-05-13 06:33:19 +0000 | [diff] [blame] | 509 | const struct BB_applet *a = applets; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 510 | |
Pavel Roskin | 9c5fcc3 | 2000-07-17 23:45:12 +0000 | [diff] [blame^] | 511 | fprintf(stderr, "%s\n\n" |
Erik Andersen | 330fd2b | 2000-05-19 05:35:19 +0000 | [diff] [blame] | 512 | "Usage: busybox [function] [arguments]...\n" |
| 513 | " or: [function] [arguments]...\n\n" |
John Beppu | b4f8606 | 2000-04-13 03:36:01 +0000 | [diff] [blame] | 514 | "\tBusyBox is a multi-call binary that combines many common Unix\n" |
| 515 | "\tutilities into a single executable. Most people will create a\n" |
| 516 | "\tlink to busybox for each function they wish to use, and BusyBox\n" |
Erik Andersen | 330fd2b | 2000-05-19 05:35:19 +0000 | [diff] [blame] | 517 | "\twill act like whatever it was invoked as.\n" |
Pavel Roskin | 9c5fcc3 | 2000-07-17 23:45:12 +0000 | [diff] [blame^] | 518 | "\nCurrently defined functions:\n", full_version); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 519 | |
| 520 | while (a->name != 0) { |
| 521 | col += |
| 522 | fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "), |
| 523 | (a++)->name); |
| 524 | if (col > 60 && a->name != 0) { |
| 525 | fprintf(stderr, ",\n"); |
| 526 | col = 0; |
| 527 | } |
| 528 | } |
| 529 | fprintf(stderr, "\n\n"); |
| 530 | exit(-1); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 531 | } |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 532 | /* If we've already been here once, exit now */ |
| 533 | been_there_done_that = 1; |
| 534 | return (main(argc, argv)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 535 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 536 | |
| 537 | /* |
| 538 | Local Variables: |
| 539 | c-file-style: "linux" |
| 540 | c-basic-offset: 4 |
| 541 | tab-width: 4 |
| 542 | End: |
| 543 | */ |