1 /* vi: set sw=4 ts=4: */
8 #undef BB_FEATURE_LINUXRC
11 static int been_there_done_that = 0;
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
20 void exit(int status) __attribute__ ((noreturn));
25 void abort(void) __attribute__ ((__noreturn__));
30 int atexit(void (*__func) (void))
34 void *__libc_stack_end;
37 static const struct Applet applets[] = {
39 #ifdef BB_BASENAME //usr/bin/basename
40 {"basename", basename_main, _BB_DIR_USR_BIN},
42 #ifdef BB_BUSYBOX //bin
43 {"busybox", busybox_main, _BB_DIR_BIN},
45 #ifdef BB_BLOCK_DEVICE //sbin
46 {"block_device", block_device_main, _BB_DIR_SBIN},
49 {"cat", cat_main, _BB_DIR_BIN},
51 #ifdef BB_CHMOD_CHOWN_CHGRP //bin
52 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
54 #ifdef BB_CHMOD_CHOWN_CHGRP //bin
55 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
57 #ifdef BB_CHMOD_CHOWN_CHGRP //bin
58 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
60 #ifdef BB_CHROOT //sbin
61 {"chroot", chroot_main, _BB_DIR_SBIN},
63 #ifdef BB_CLEAR //usr/bin
64 {"clear", clear_main, _BB_DIR_USR_BIN},
66 #ifdef BB_CHVT //usr/bin
67 {"chvt", chvt_main, _BB_DIR_USR_BIN},
70 {"cp", cp_mv_main, _BB_DIR_BIN},
73 {"mv", cp_mv_main, _BB_DIR_BIN},
76 {"date", date_main, _BB_DIR_BIN},
79 {"dd", dd_main, _BB_DIR_BIN},
82 {"df", df_main, _BB_DIR_BIN},
84 #ifdef BB_DIRNAME //usr/bin
85 {"dirname", dirname_main, _BB_DIR_USR_BIN},
88 {"dmesg", dmesg_main, _BB_DIR_BIN},
91 {"du", du_main, _BB_DIR_BIN},
93 #ifdef BB_DUTMP //usr/sbin
94 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
97 {"echo", echo_main, _BB_DIR_BIN},
99 #ifdef BB_FBSET //usr/sbin
100 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
102 #ifdef BB_FDFLUSH //bin
103 {"fdflush", fdflush_main, _BB_DIR_BIN},
105 #ifdef BB_FIND //usr/bin
106 {"find", find_main, _BB_DIR_USR_BIN},
108 #ifdef BB_FREE //usr/bin
109 {"free", free_main, _BB_DIR_USR_BIN},
111 #ifdef BB_FREERAMDISK //sbin
112 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
114 #ifdef BB_DEALLOCVT //usr/bin
115 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
117 #ifdef BB_FSCK_MINIX //sbin
118 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
120 #ifdef BB_MKFS_MINIX //sbin
121 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
124 {"grep", grep_main, _BB_DIR_BIN},
126 #ifdef BB_HALT //sbin
127 {"halt", halt_main, _BB_DIR_SBIN},
130 {"head", head_main, _BB_DIR_BIN},
132 #ifdef BB_HOSTID //usr/bin
133 {"hostid", hostid_main, _BB_DIR_USR_BIN},
135 #ifdef BB_HOSTNAME //bin
136 {"hostname", hostname_main, _BB_DIR_BIN},
138 #ifdef BB_INIT //sbin
139 {"init", init_main, _BB_DIR_SBIN},
141 #ifdef BB_INSMOD //sbin
142 {"insmod", insmod_main, _BB_DIR_SBIN},
144 #ifdef BB_FEATURE_LINUXRC //
145 {"linuxrc", init_main, _BB_DIR_ROOT},
148 {"kill", kill_main, _BB_DIR_BIN},
150 #ifdef BB_KILLALL //usr/bin
151 {"killall", kill_main, _BB_DIR_USR_BIN},
153 #ifdef BB_LENGTH //usr/bin
154 {"length", length_main, _BB_DIR_USR_BIN},
157 {"ln", ln_main, _BB_DIR_BIN},
159 #ifdef BB_LOADACM //usr/bin
160 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
162 #ifdef BB_LOADFONT //usr/bin
163 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
165 #ifdef BB_LOADKMAP //sbin
166 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
169 {"ls", ls_main, _BB_DIR_BIN},
171 #ifdef BB_LSMOD //sbin
172 {"lsmod", lsmod_main, _BB_DIR_SBIN},
174 #ifdef BB_MAKEDEVS //sbin
175 {"makedevs", makedevs_main, _BB_DIR_SBIN},
177 #ifdef BB_MATH //usr/bin
178 {"math", math_main, _BB_DIR_USR_BIN},
180 #ifdef BB_MKDIR //bin
181 {"mkdir", mkdir_main, _BB_DIR_BIN},
183 #ifdef BB_MKFIFO //usr/bin
184 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
186 #ifdef BB_MKNOD //bin
187 {"mknod", mknod_main, _BB_DIR_BIN},
189 #ifdef BB_MKSWAP //sbin
190 {"mkswap", mkswap_main, _BB_DIR_SBIN},
192 #ifdef BB_MNC //usr/bin
193 {"mnc", mnc_main, _BB_DIR_USR_BIN},
196 {"more", more_main, _BB_DIR_BIN},
198 #ifdef BB_MOUNT //bin
199 {"mount", mount_main, _BB_DIR_BIN},
202 {"mt", mt_main, _BB_DIR_BIN},
204 #ifdef BB_NSLOOKUP //usr/bin
205 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
208 {"ping", ping_main, _BB_DIR_BIN},
210 #ifdef BB_POWEROFF //sbin
211 {"poweroff", poweroff_main, _BB_DIR_SBIN},
213 #ifdef BB_PRINTF //usr/bin
214 {"printf", printf_main, _BB_DIR_USR_BIN},
217 {"ps", ps_main, _BB_DIR_BIN},
220 {"pwd", pwd_main, _BB_DIR_BIN},
222 #ifdef BB_REBOOT //sbin
223 {"reboot", reboot_main, _BB_DIR_SBIN},
226 {"rm", rm_main, _BB_DIR_BIN},
228 #ifdef BB_RMDIR //bin
229 {"rmdir", rmdir_main, _BB_DIR_BIN},
231 #ifdef BB_RMMOD //sbin
232 {"rmmod", rmmod_main, _BB_DIR_SBIN},
235 {"sed", sed_main, _BB_DIR_BIN},
238 {"sh", shell_main, _BB_DIR_BIN},
240 #ifdef BB_SFDISK //sbin
241 {"fdisk", sfdisk_main, _BB_DIR_SBIN},
242 #ifdef BB_SFDISK //sbin
244 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
246 #ifdef BB_SLEEP //bin
247 {"sleep", sleep_main, _BB_DIR_BIN},
250 {"sort", sort_main, _BB_DIR_BIN},
253 {"sync", sync_main, _BB_DIR_BIN},
255 #ifdef BB_SYSLOGD //sbin
256 {"syslogd", syslogd_main, _BB_DIR_SBIN},
258 #ifdef BB_LOGGER //usr/bin
259 {"logger", logger_main, _BB_DIR_USR_BIN},
261 #ifdef BB_LOGNAME //usr/bin
262 {"logname", logname_main, _BB_DIR_USR_BIN},
264 #ifdef BB_SWAPONOFF //sbin
265 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
267 #ifdef BB_SWAPONOFF //sbin
268 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
270 #ifdef BB_TAIL //usr/bin
271 {"tail", tail_main, _BB_DIR_USR_BIN},
274 {"tar", tar_main, _BB_DIR_BIN},
276 #ifdef BB_TELNET //usr/bin
277 {"telnet", telnet_main, _BB_DIR_USR_BIN},
279 #ifdef BB_TEST //usr/bin
280 {"[", test_main, _BB_DIR_USR_BIN},
282 #ifdef BB_TEST //usr/bin
283 {"test", test_main, _BB_DIR_USR_BIN},
286 {"tee", tee_main, _BB_DIR_BIN},
288 #ifdef BB_TOUCH //usr/bin
289 {"touch", touch_main, _BB_DIR_USR_BIN},
291 #ifdef BB_TR //usr/bin
292 {"tr", tr_main, _BB_DIR_USR_BIN},
294 #ifdef BB_TRUE_FALSE //bin
295 {"true", true_main, _BB_DIR_BIN},
297 #ifdef BB_TRUE_FALSE //bin
298 {"false", false_main, _BB_DIR_BIN},
300 #ifdef BB_TTY //usr/bin
301 {"tty", tty_main, _BB_DIR_USR_BIN},
303 #ifdef BB_UMOUNT //bin
304 {"umount", umount_main, _BB_DIR_BIN},
306 #ifdef BB_UNAME //bin
307 {"uname", uname_main, _BB_DIR_BIN},
309 #ifdef BB_UPTIME //usr/bin
310 {"uptime", uptime_main, _BB_DIR_USR_BIN},
313 {"uniq", uniq_main, _BB_DIR_BIN},
315 #ifdef BB_UPDATE //sbin
316 {"update", update_main, _BB_DIR_SBIN},
318 #ifdef BB_WC //usr/bin
319 {"wc", wc_main, _BB_DIR_USR_BIN},
321 #ifdef BB_WHOAMI //usr/bin
322 {"whoami", whoami_main, _BB_DIR_USR_BIN},
324 #ifdef BB_YES //usr/bin
325 {"yes", yes_main, _BB_DIR_USR_BIN},
327 #ifdef BB_GUNZIP //bin
328 {"zcat", gunzip_main, _BB_DIR_BIN},
330 #ifdef BB_GUNZIP //bin
331 {"gunzip", gunzip_main, _BB_DIR_BIN},
334 {"gzip", gzip_main, _BB_DIR_BIN},
341 int main(int argc, char **argv)
345 const struct Applet *a = applets;
347 for (s = name = argv[0]; *s != '\0';) {
354 while (a->name != 0) {
355 if (strcmp(name, a->name) == 0) {
358 status = ((*(a->main)) (argc, argv));
360 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
362 fprintf(stderr, "\n");
367 exit(busybox_main(argc, argv));
371 int busybox_main(int argc, char **argv)
378 if (been_there_done_that == 1 || argc < 1) {
379 const struct Applet *a = applets;
381 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
383 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
384 fprintf(stderr, " or: [function] [arguments]...\n\n");
386 "\tMost people will create a link to busybox for each\n"
387 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
388 fprintf(stderr, "\nCurrently defined functions:\n");
390 while (a->name != 0) {
392 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
394 if (col > 60 && a->name != 0) {
395 fprintf(stderr, ",\n");
399 fprintf(stderr, "\n\n");
402 /* If we've already been here once, exit now */
403 been_there_done_that = 1;
404 return (main(argc, argv));
410 c-file-style: "linux"