1 /* vi: set sw=4 ts=4: */
7 static int been_there_done_that = 0;
9 /* It has been alledged that doing such things can
10 * help reduce binary size when staticly linking,
11 * of course with glibc, this is unlikely as long
12 * as we use things like printf -- perhaps a printf
13 * replacement may be in order
16 void exit(int status) __attribute__ ((noreturn));
21 void abort(void) __attribute__ ((__noreturn__));
26 int atexit(void (*__func) (void))
30 void *__libc_stack_end;
33 static const struct Applet applets[] = {
36 {"basename", basename_main, _BB_DIR_USR_BIN},
39 {"busybox", busybox_main, _BB_DIR_BIN},
41 #ifdef BB_BLOCK_DEVICE
42 {"block_device", block_device_main, _BB_DIR_SBIN},
45 {"cat", cat_main, _BB_DIR_BIN},
47 #ifdef BB_CHMOD_CHOWN_CHGRP
48 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
50 #ifdef BB_CHMOD_CHOWN_CHGRP
51 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
53 #ifdef BB_CHMOD_CHOWN_CHGRP
54 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
57 {"chroot", chroot_main, _BB_DIR_SBIN},
60 {"clear", clear_main, _BB_DIR_USR_BIN},
63 {"chvt", chvt_main, _BB_DIR_USR_BIN},
66 {"cp", cp_mv_main, _BB_DIR_BIN},
69 {"date", date_main, _BB_DIR_BIN},
72 {"dd", dd_main, _BB_DIR_BIN},
75 {"df", df_main, _BB_DIR_BIN},
78 {"dirname", dirname_main, _BB_DIR_USR_BIN},
81 {"dmesg", dmesg_main, _BB_DIR_BIN},
84 {"du", du_main, _BB_DIR_BIN},
87 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
90 {"echo", echo_main, _BB_DIR_BIN},
93 {"false", false_main, _BB_DIR_BIN},
96 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
99 {"fdflush", fdflush_main, _BB_DIR_BIN},
102 {"find", find_main, _BB_DIR_USR_BIN},
105 {"free", free_main, _BB_DIR_USR_BIN},
107 #ifdef BB_FREERAMDISK
108 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
111 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
114 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
117 {"grep", grep_main, _BB_DIR_BIN},
120 {"gunzip", gunzip_main, _BB_DIR_BIN},
123 {"gzip", gzip_main, _BB_DIR_BIN},
126 {"halt", halt_main, _BB_DIR_SBIN},
129 {"head", head_main, _BB_DIR_BIN},
132 {"hostid", hostid_main, _BB_DIR_USR_BIN},
135 {"hostname", hostname_main, _BB_DIR_BIN},
138 {"init", init_main, _BB_DIR_SBIN},
141 {"insmod", insmod_main, _BB_DIR_SBIN},
144 {"kill", kill_main, _BB_DIR_BIN},
147 {"killall", kill_main, _BB_DIR_USR_BIN},
150 {"length", length_main, _BB_DIR_USR_BIN},
153 {"linuxrc", init_main, _BB_DIR_ROOT},
156 {"ln", ln_main, _BB_DIR_BIN},
159 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
162 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
165 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
168 {"logger", logger_main, _BB_DIR_USR_BIN},
171 {"logname", logname_main, _BB_DIR_USR_BIN},
174 {"ls", ls_main, _BB_DIR_BIN},
177 {"lsmod", lsmod_main, _BB_DIR_SBIN},
180 {"makedevs", makedevs_main, _BB_DIR_SBIN},
183 {"math", math_main, _BB_DIR_USR_BIN},
186 {"mkdir", mkdir_main, _BB_DIR_BIN},
189 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
192 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
195 {"mknod", mknod_main, _BB_DIR_BIN},
198 {"mkswap", mkswap_main, _BB_DIR_SBIN},
201 {"mktemp", mktemp_main, _BB_DIR_BIN},
204 {"mnc", mnc_main, _BB_DIR_USR_BIN},
207 {"more", more_main, _BB_DIR_BIN},
210 {"mount", mount_main, _BB_DIR_BIN},
213 {"mt", mt_main, _BB_DIR_BIN},
216 {"mv", cp_mv_main, _BB_DIR_BIN},
219 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
222 {"ping", ping_main, _BB_DIR_BIN},
225 {"poweroff", poweroff_main, _BB_DIR_SBIN},
228 {"printf", printf_main, _BB_DIR_USR_BIN},
231 {"ps", ps_main, _BB_DIR_BIN},
234 {"pwd", pwd_main, _BB_DIR_BIN},
237 {"reboot", reboot_main, _BB_DIR_SBIN},
240 {"rm", rm_main, _BB_DIR_BIN},
243 {"rmdir", rmdir_main, _BB_DIR_BIN},
246 {"rmmod", rmmod_main, _BB_DIR_SBIN},
249 {"sed", sed_main, _BB_DIR_BIN},
251 #ifdef BB_SETKEYCODES
252 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
255 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
258 {"sh", shell_main, _BB_DIR_BIN},
261 {"sleep", sleep_main, _BB_DIR_BIN},
264 {"sort", sort_main, _BB_DIR_BIN},
267 {"sync", sync_main, _BB_DIR_BIN},
270 {"syslogd", syslogd_main, _BB_DIR_SBIN},
273 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
276 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
279 {"tail", tail_main, _BB_DIR_USR_BIN},
282 {"tar", tar_main, _BB_DIR_BIN},
285 {"telnet", telnet_main, _BB_DIR_USR_BIN},
288 {"test", test_main, _BB_DIR_USR_BIN},
291 {"tee", tee_main, _BB_DIR_BIN},
294 {"touch", touch_main, _BB_DIR_USR_BIN},
297 {"tr", tr_main, _BB_DIR_USR_BIN},
300 {"true", true_main, _BB_DIR_BIN},
303 {"tty", tty_main, _BB_DIR_USR_BIN},
306 {"umount", umount_main, _BB_DIR_BIN},
309 {"uname", uname_main, _BB_DIR_BIN},
312 {"uniq", uniq_main, _BB_DIR_USR_BIN},
315 {"update", update_main, _BB_DIR_SBIN},
318 {"uptime", uptime_main, _BB_DIR_USR_BIN},
321 {"usleep", usleep_main, _BB_DIR_BIN},
324 {"wc", wc_main, _BB_DIR_USR_BIN},
327 {"whoami", whoami_main, _BB_DIR_USR_BIN},
330 {"yes", yes_main, _BB_DIR_USR_BIN},
333 {"zcat", gunzip_main, _BB_DIR_BIN},
336 {"[", test_main, _BB_DIR_USR_BIN},
343 int main(int argc, char **argv)
347 const struct Applet *a = applets;
349 for (s = name = argv[0]; *s != '\0';) {
356 while (a->name != 0) {
357 if (strcmp(name, a->name) == 0) {
360 status = ((*(a->main)) (argc, argv));
362 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
364 fprintf(stderr, "\n");
369 exit(busybox_main(argc, argv));
373 int busybox_main(int argc, char **argv)
380 if (been_there_done_that == 1 || argc < 1) {
381 const struct Applet *a = applets;
383 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
385 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
386 fprintf(stderr, " or: [function] [arguments]...\n\n");
388 "\tBusyBox is a multi-call binary that combines many common Unix\n"
389 "\tutilities into a single executable. Most people will create a\n"
390 "\tlink to busybox for each function they wish to use, and BusyBox\n"
391 "\twill act like whatever it was invoked as.\n");
392 fprintf(stderr, "\nCurrently defined functions:\n");
394 while (a->name != 0) {
396 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
398 if (col > 60 && a->name != 0) {
399 fprintf(stderr, ",\n");
403 fprintf(stderr, "\n\n");
406 /* If we've already been here once, exit now */
407 been_there_done_that = 1;
408 return (main(argc, argv));
414 c-file-style: "linux"