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 {"cut", cut_main, _BB_DIR_USR_BIN},
72 {"date", date_main, _BB_DIR_BIN},
75 {"dd", dd_main, _BB_DIR_BIN},
78 {"df", df_main, _BB_DIR_BIN},
81 {"dirname", dirname_main, _BB_DIR_USR_BIN},
84 {"dmesg", dmesg_main, _BB_DIR_BIN},
87 {"du", du_main, _BB_DIR_BIN},
90 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
93 {"echo", echo_main, _BB_DIR_BIN},
96 {"false", false_main, _BB_DIR_BIN},
99 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
102 {"fdflush", fdflush_main, _BB_DIR_BIN},
105 {"find", find_main, _BB_DIR_USR_BIN},
108 {"free", free_main, _BB_DIR_USR_BIN},
110 #ifdef BB_FREERAMDISK
111 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
114 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
117 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
120 {"grep", grep_main, _BB_DIR_BIN},
123 {"gunzip", gunzip_main, _BB_DIR_BIN},
126 {"gzip", gzip_main, _BB_DIR_BIN},
129 {"halt", halt_main, _BB_DIR_SBIN},
132 {"head", head_main, _BB_DIR_BIN},
135 {"hostid", hostid_main, _BB_DIR_USR_BIN},
138 {"hostname", hostname_main, _BB_DIR_BIN},
141 {"id", id_main, _BB_DIR_USR_BIN},
144 {"init", init_main, _BB_DIR_SBIN},
147 {"insmod", insmod_main, _BB_DIR_SBIN},
150 {"kill", kill_main, _BB_DIR_BIN},
153 {"killall", kill_main, _BB_DIR_USR_BIN},
156 {"length", length_main, _BB_DIR_USR_BIN},
159 {"linuxrc", init_main, _BB_DIR_ROOT},
162 {"ln", ln_main, _BB_DIR_BIN},
165 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
168 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
171 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
174 {"logger", logger_main, _BB_DIR_USR_BIN},
177 {"logname", logname_main, _BB_DIR_USR_BIN},
180 {"ls", ls_main, _BB_DIR_BIN},
183 {"lsmod", lsmod_main, _BB_DIR_SBIN},
186 {"makedevs", makedevs_main, _BB_DIR_SBIN},
189 {"math", math_main, _BB_DIR_USR_BIN},
192 {"mkdir", mkdir_main, _BB_DIR_BIN},
195 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
198 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
201 {"mknod", mknod_main, _BB_DIR_BIN},
204 {"mkswap", mkswap_main, _BB_DIR_SBIN},
207 {"mktemp", mktemp_main, _BB_DIR_BIN},
210 {"nc", nc_main, _BB_DIR_USR_BIN},
213 {"more", more_main, _BB_DIR_BIN},
216 {"mount", mount_main, _BB_DIR_BIN},
219 {"mt", mt_main, _BB_DIR_BIN},
222 {"mv", cp_mv_main, _BB_DIR_BIN},
225 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
228 {"ping", ping_main, _BB_DIR_BIN},
231 {"poweroff", poweroff_main, _BB_DIR_SBIN},
234 {"printf", printf_main, _BB_DIR_USR_BIN},
237 {"ps", ps_main, _BB_DIR_BIN},
240 {"pwd", pwd_main, _BB_DIR_BIN},
243 {"reboot", reboot_main, _BB_DIR_SBIN},
246 {"rm", rm_main, _BB_DIR_BIN},
249 {"rmdir", rmdir_main, _BB_DIR_BIN},
252 {"rmmod", rmmod_main, _BB_DIR_SBIN},
255 {"sed", sed_main, _BB_DIR_BIN},
257 #ifdef BB_SETKEYCODES
258 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
261 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
264 {"sh", shell_main, _BB_DIR_BIN},
267 {"sleep", sleep_main, _BB_DIR_BIN},
270 {"sort", sort_main, _BB_DIR_BIN},
273 {"sync", sync_main, _BB_DIR_BIN},
276 {"syslogd", syslogd_main, _BB_DIR_SBIN},
279 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
282 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
285 {"tail", tail_main, _BB_DIR_USR_BIN},
288 {"tar", tar_main, _BB_DIR_BIN},
291 {"telnet", telnet_main, _BB_DIR_USR_BIN},
294 {"test", test_main, _BB_DIR_USR_BIN},
297 {"tee", tee_main, _BB_DIR_BIN},
300 {"touch", touch_main, _BB_DIR_USR_BIN},
303 {"tr", tr_main, _BB_DIR_USR_BIN},
306 {"true", true_main, _BB_DIR_BIN},
309 {"tty", tty_main, _BB_DIR_USR_BIN},
312 {"umount", umount_main, _BB_DIR_BIN},
315 {"uname", uname_main, _BB_DIR_BIN},
318 {"uniq", uniq_main, _BB_DIR_USR_BIN},
321 {"update", update_main, _BB_DIR_SBIN},
324 {"uptime", uptime_main, _BB_DIR_USR_BIN},
327 {"usleep", usleep_main, _BB_DIR_BIN},
330 {"wc", wc_main, _BB_DIR_USR_BIN},
333 {"whoami", whoami_main, _BB_DIR_USR_BIN},
336 {"yes", yes_main, _BB_DIR_USR_BIN},
339 {"zcat", gunzip_main, _BB_DIR_BIN},
342 {"[", test_main, _BB_DIR_USR_BIN},
349 int main(int argc, char **argv)
353 const struct Applet *a = applets;
355 for (s = name = argv[0]; *s != '\0';) {
362 while (a->name != 0) {
363 if (strcmp(name, a->name) == 0) {
366 status = ((*(a->main)) (argc, argv));
368 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
370 fprintf(stderr, "\n");
375 exit(busybox_main(argc, argv));
379 int busybox_main(int argc, char **argv)
386 if (been_there_done_that == 1 || argc < 1) {
387 const struct Applet *a = applets;
389 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
391 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
392 fprintf(stderr, " or: [function] [arguments]...\n\n");
394 "\tBusyBox is a multi-call binary that combines many common Unix\n"
395 "\tutilities into a single executable. Most people will create a\n"
396 "\tlink to busybox for each function they wish to use, and BusyBox\n"
397 "\twill act like whatever it was invoked as.\n");
398 fprintf(stderr, "\nCurrently defined functions:\n");
400 while (a->name != 0) {
402 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
404 if (col > 60 && a->name != 0) {
405 fprintf(stderr, ",\n");
409 fprintf(stderr, "\n\n");
412 /* If we've already been here once, exit now */
413 been_there_done_that = 1;
414 return (main(argc, argv));
420 c-file-style: "linux"