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 | |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 7 | #ifndef BB_INIT |
| 8 | #undef BB_FEATURE_LINUXRC |
| 9 | #endif |
| 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 | |
| 37 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 38 | static const struct Applet applets[] = { |
| 39 | |
Erik Andersen | e272915 | 2000-02-18 21:34:17 +0000 | [diff] [blame] | 40 | #ifdef BB_BASENAME //usr/bin/basename |
| 41 | {"basename", basename_main}, |
| 42 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 43 | #ifdef BB_BUSYBOX //bin |
| 44 | {"busybox", busybox_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 45 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 46 | #ifdef BB_BLOCK_DEVICE //sbin |
| 47 | {"block_device", block_device_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 48 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 49 | #ifdef BB_CAT //bin |
| 50 | {"cat", cat_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 51 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 52 | #ifdef BB_CHMOD_CHOWN_CHGRP //bin |
| 53 | {"chmod", chmod_chown_chgrp_main}, |
| 54 | {"chown", chmod_chown_chgrp_main}, |
| 55 | {"chgrp", chmod_chown_chgrp_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 56 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 57 | #ifdef BB_CHROOT //sbin |
| 58 | {"chroot", chroot_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 59 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 60 | #ifdef BB_CLEAR //usr/bin |
| 61 | {"clear", clear_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 62 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 63 | #ifdef BB_CHVT //usr/bin |
| 64 | {"chvt", chvt_main}, |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 65 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 66 | #ifdef BB_CP_MV //bin |
| 67 | {"cp", cp_mv_main}, |
| 68 | {"mv", cp_mv_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 69 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 70 | #ifdef BB_DATE //bin |
| 71 | {"date", date_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 72 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 73 | #ifdef BB_DD //bin |
| 74 | {"dd", dd_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 75 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 76 | #ifdef BB_DF //bin |
| 77 | {"df", df_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 78 | #endif |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 79 | #ifdef BB_DIRNAME //usr/bin |
| 80 | {"dirname", dirname_main}, |
| 81 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 82 | #ifdef BB_DMESG //bin |
| 83 | {"dmesg", dmesg_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 84 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 85 | #ifdef BB_DU //bin |
| 86 | {"du", du_main}, |
John Beppu | 7a98606 | 1999-12-09 18:29:29 +0000 | [diff] [blame] | 87 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 88 | #ifdef BB_DUTMP //usr/sbin |
| 89 | {"dutmp", dutmp_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 90 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 91 | #ifdef BB_FBSET //usr/sbin |
| 92 | {"fbset", fbset_main}, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 93 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 94 | #ifdef BB_FDFLUSH //bin |
| 95 | {"fdflush", fdflush_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 96 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 97 | #ifdef BB_FIND //usr/bin |
| 98 | {"find", find_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 99 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 100 | #ifdef BB_FREE //usr/bin |
| 101 | {"free", free_main}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 102 | #endif |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 103 | #ifdef BB_FREERAMDISK //sbin |
| 104 | {"freeramdisk", freeramdisk_main}, |
| 105 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 106 | #ifdef BB_DEALLOCVT //usr/bin |
| 107 | {"deallocvt", deallocvt_main}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 108 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 109 | #ifdef BB_FSCK_MINIX //sbin |
| 110 | {"fsck.minix", fsck_minix_main}, |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 111 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 112 | #ifdef BB_MKFS_MINIX //sbin |
| 113 | {"mkfs.minix", mkfs_minix_main}, |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 114 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 115 | #ifdef BB_GREP //bin |
| 116 | {"grep", grep_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 117 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 118 | #ifdef BB_HALT //sbin |
| 119 | {"halt", halt_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 120 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 121 | #ifdef BB_HEAD //bin |
| 122 | {"head", head_main}, |
John Beppu | 3157b1f | 1999-12-10 07:42:50 +0000 | [diff] [blame] | 123 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 124 | #ifdef BB_HOSTID //usr/bin |
| 125 | {"hostid", hostid_main}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 126 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 127 | #ifdef BB_HOSTNAME //bin |
| 128 | {"hostname", hostname_main}, |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 129 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 130 | #ifdef BB_INIT //sbin |
| 131 | {"init", init_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 132 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 133 | #ifdef BB_INSMOD //sbin |
| 134 | {"insmod", insmod_main}, |
Erik Andersen | 6da0ae8 | 1999-12-17 01:08:27 +0000 | [diff] [blame] | 135 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 136 | #ifdef BB_FEATURE_LINUXRC // |
| 137 | {"linuxrc", init_main}, |
Eric Andersen | 6a76e65 | 1999-11-19 05:31:45 +0000 | [diff] [blame] | 138 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 139 | #ifdef BB_KILL //bin |
| 140 | {"kill", kill_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 141 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 142 | #ifdef BB_LENGTH //usr/bin |
| 143 | {"length", length_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 144 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 145 | #ifdef BB_LN //bin |
| 146 | {"ln", ln_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 147 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 148 | #ifdef BB_LOADACM //usr/bin |
| 149 | {"loadacm", loadacm_main}, |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 150 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 151 | #ifdef BB_LOADFONT //usr/bin |
| 152 | {"loadfont", loadfont_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 153 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 154 | #ifdef BB_LOADKMAP //sbin |
| 155 | {"loadkmap", loadkmap_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 156 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 157 | #ifdef BB_LS //bin |
| 158 | {"ls", ls_main}, |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 159 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 160 | #ifdef BB_LSMOD //sbin |
| 161 | {"lsmod", lsmod_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 162 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 163 | #ifdef BB_MAKEDEVS //sbin |
| 164 | {"makedevs", makedevs_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 165 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 166 | #ifdef BB_MATH //usr/bin |
| 167 | {"math", math_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 168 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 169 | #ifdef BB_MKDIR //bin |
| 170 | {"mkdir", mkdir_main}, |
| 171 | #endif |
| 172 | #ifdef BB_MKFIFO //usr/bin |
| 173 | {"mkfifo", mkfifo_main}, |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 174 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 175 | #ifdef BB_MKNOD //bin |
| 176 | {"mknod", mknod_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 177 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 178 | #ifdef BB_MKSWAP //sbin |
| 179 | {"mkswap", mkswap_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 180 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 181 | #ifdef BB_MNC //usr/bin |
| 182 | {"mnc", mnc_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 183 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 184 | #ifdef BB_MORE //bin |
| 185 | {"more", more_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 186 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 187 | #ifdef BB_MOUNT //bin |
| 188 | {"mount", mount_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 189 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 190 | #ifdef BB_MT //bin |
| 191 | {"mt", mt_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 192 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 193 | #ifdef BB_NSLOOKUP //usr/bin |
| 194 | {"nslookup", nslookup_main}, |
John Beppu | b332e77 | 2000-01-29 12:59:01 +0000 | [diff] [blame] | 195 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 196 | #ifdef BB_PING //bin |
| 197 | {"ping", ping_main}, |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 198 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 199 | #ifdef BB_POWEROFF //sbin |
| 200 | {"poweroff", poweroff_main}, |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 201 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 202 | #ifdef BB_PRINTF //usr/bin |
| 203 | {"printf", printf_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 204 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 205 | #ifdef BB_PS //bin |
| 206 | {"ps", ps_main}, |
Eric Andersen | ef8b6c7 | 1999-10-20 08:05:35 +0000 | [diff] [blame] | 207 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 208 | #ifdef BB_PWD //bin |
| 209 | {"pwd", pwd_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 210 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 211 | #ifdef BB_REBOOT //sbin |
| 212 | {"reboot", reboot_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 213 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 214 | #ifdef BB_RM //bin |
| 215 | {"rm", rm_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 216 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 217 | #ifdef BB_RMDIR //bin |
| 218 | {"rmdir", rmdir_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 219 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 220 | #ifdef BB_RMMOD //sbin |
| 221 | {"rmmod", rmmod_main}, |
Erik Andersen | 3d7e341 | 1999-12-16 23:04:20 +0000 | [diff] [blame] | 222 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 223 | #ifdef BB_SFDISK //sbin |
| 224 | {"fdisk", sfdisk_main}, |
| 225 | {"sfdisk", sfdisk_main}, |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 226 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 227 | #ifdef BB_SED //bin |
| 228 | {"sed", sed_main}, |
Eric Andersen | c1525e8 | 1999-10-29 00:07:31 +0000 | [diff] [blame] | 229 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 230 | #ifdef BB_SLEEP //bin |
| 231 | {"sleep", sleep_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 232 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 233 | #ifdef BB_SORT //bin |
| 234 | {"sort", sort_main}, |
John Beppu | 019513a | 1999-12-22 17:57:31 +0000 | [diff] [blame] | 235 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 236 | #ifdef BB_SYNC //bin |
| 237 | {"sync", sync_main}, |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 238 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 239 | #ifdef BB_SYSLOGD //sbin |
| 240 | {"syslogd", syslogd_main}, |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 241 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 242 | #ifdef BB_LOGGER //usr/bin |
| 243 | {"logger", logger_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 244 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 245 | #ifdef BB_LOGNAME //usr/bin |
| 246 | {"logname", logname_main}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 247 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 248 | #ifdef BB_SWAPONOFF //sbin |
| 249 | {"swapon", swap_on_off_main}, |
| 250 | {"swapoff", swap_on_off_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 251 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 252 | #ifdef BB_TAIL //usr/bin |
| 253 | {"tail", tail_main}, |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 254 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 255 | #ifdef BB_TAR //bin |
| 256 | {"tar", tar_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 257 | #endif |
Erik Andersen | f7c49ef | 2000-02-22 17:17:45 +0000 | [diff] [blame] | 258 | #ifdef BB_TELNET //usr/bin |
| 259 | {"telnet", telnet_main}, |
| 260 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 261 | #ifdef BB_TEE //bin |
| 262 | {"tee", tee_main}, |
John Beppu | 059f152 | 1999-12-10 05:27:16 +0000 | [diff] [blame] | 263 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 264 | #ifdef BB_TOUCH //usr/bin |
| 265 | {"touch", touch_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 266 | #endif |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 267 | #ifdef BB_TR //usr/bin |
| 268 | {"tr", tr_main}, |
| 269 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 270 | #ifdef BB_TRUE_FALSE //bin |
| 271 | {"true", true_main}, |
| 272 | {"false", false_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 273 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 274 | #ifdef BB_TTY //usr/bin |
| 275 | {"tty", tty_main}, |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 276 | #endif |
Erik Andersen | 66be5e7 | 2000-03-05 07:52:05 +0000 | [diff] [blame] | 277 | #ifdef BB_UMOUNT //bin |
| 278 | {"umount", umount_main}, |
| 279 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 280 | #ifdef BB_UNAME //bin |
| 281 | {"uname", uname_main}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 282 | #endif |
Erik Andersen | 66be5e7 | 2000-03-05 07:52:05 +0000 | [diff] [blame] | 283 | #ifdef BB_UPTIME //usr/bin |
| 284 | {"uptime", uptime_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 285 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 286 | #ifdef BB_UNIQ //bin |
| 287 | {"uniq", uniq_main}, |
John Beppu | abb4772 | 2000-01-06 00:48:21 +0000 | [diff] [blame] | 288 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 289 | #ifdef BB_UPDATE //sbin |
| 290 | {"update", update_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 291 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 292 | #ifdef BB_WC //usr/bin |
| 293 | {"wc", wc_main}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 294 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 295 | #ifdef BB_WHOAMI //usr/bin |
| 296 | {"whoami", whoami_main}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 297 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 298 | #ifdef BB_YES //usr/bin |
| 299 | {"yes", yes_main}, |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 300 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 301 | #ifdef BB_GUNZIP //bin |
| 302 | {"zcat", gunzip_main}, |
| 303 | {"gunzip", gunzip_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 304 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 305 | #ifdef BB_GZIP //bin |
| 306 | {"gzip", gzip_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 307 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 308 | {0} |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 311 | |
| 312 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 313 | int main(int argc, char **argv) |
| 314 | { |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 315 | char *s = argv[0]; |
| 316 | char *name = argv[0]; |
| 317 | const struct Applet *a = applets; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 318 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 319 | while (*s != '\0') { |
| 320 | if (*s++ == '/') |
| 321 | name = s; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 322 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 323 | |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 324 | *argv = name; |
| 325 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 326 | while (a->name != 0) { |
| 327 | if (strcmp(name, a->name) == 0) { |
| 328 | int status; |
| 329 | |
| 330 | status = ((*(a->main)) (argc, argv)); |
| 331 | if (status < 0) { |
| 332 | fprintf(stderr, "%s: %s\n", a->name, strerror(errno)); |
| 333 | } |
| 334 | fprintf(stderr, "\n"); |
| 335 | exit(status); |
| 336 | } |
| 337 | a++; |
| 338 | } |
| 339 | exit(busybox_main(argc, argv)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
| 343 | int busybox_main(int argc, char **argv) |
| 344 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 345 | int col = 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 346 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 347 | argc--; |
| 348 | argv++; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 349 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 350 | if (been_there_done_that == 1 || argc < 1) { |
| 351 | const struct Applet *a = applets; |
| 352 | |
| 353 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
| 354 | BB_VER, BB_BT); |
| 355 | fprintf(stderr, "Usage: busybox [function] [arguments]...\n"); |
| 356 | fprintf(stderr, " or: [function] [arguments]...\n\n"); |
| 357 | fprintf(stderr, |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 358 | "\tMost people will create a link to busybox for each\n" |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 359 | "\tfunction name, and busybox will act like whatever you invoke it as.\n"); |
| 360 | fprintf(stderr, "\nCurrently defined functions:\n"); |
| 361 | |
| 362 | while (a->name != 0) { |
| 363 | col += |
| 364 | fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "), |
| 365 | (a++)->name); |
| 366 | if (col > 60 && a->name != 0) { |
| 367 | fprintf(stderr, ",\n"); |
| 368 | col = 0; |
| 369 | } |
| 370 | } |
| 371 | fprintf(stderr, "\n\n"); |
| 372 | exit(-1); |
| 373 | } else { |
| 374 | /* If we've already been here once, exit now */ |
| 375 | been_there_done_that = 1; |
| 376 | return (main(argc, argv)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 377 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 378 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 379 | |
| 380 | /* |
| 381 | Local Variables: |
| 382 | c-file-style: "linux" |
| 383 | c-basic-offset: 4 |
| 384 | tab-width: 4 |
| 385 | End: |
| 386 | */ |