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 const struct BB_applet applets[] = {
36 {"ar", ar_main, _BB_DIR_USR_BIN},
39 {"basename", basename_main, _BB_DIR_USR_BIN},
41 {"busybox", busybox_main, _BB_DIR_BIN},
42 #ifdef BB_BLOCK_DEVICE
43 {"block_device", block_device_main, _BB_DIR_SBIN},
46 {"cat", cat_main, _BB_DIR_BIN},
48 #ifdef BB_CHMOD_CHOWN_CHGRP
49 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
51 #ifdef BB_CHMOD_CHOWN_CHGRP
52 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
54 #ifdef BB_CHMOD_CHOWN_CHGRP
55 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
58 {"chroot", chroot_main, _BB_DIR_SBIN},
61 {"clear", clear_main, _BB_DIR_USR_BIN},
64 {"chvt", chvt_main, _BB_DIR_USR_BIN},
67 {"cp", cp_mv_main, _BB_DIR_BIN},
70 {"cut", cut_main, _BB_DIR_USR_BIN},
73 {"date", date_main, _BB_DIR_BIN},
76 {"dc", dc_main, _BB_DIR_USR_BIN},
79 {"dd", dd_main, _BB_DIR_BIN},
82 {"df", df_main, _BB_DIR_BIN},
85 {"dirname", dirname_main, _BB_DIR_USR_BIN},
88 {"dmesg", dmesg_main, _BB_DIR_BIN},
91 {"du", du_main, _BB_DIR_BIN},
94 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
97 {"echo", echo_main, _BB_DIR_BIN},
100 {"false", false_main, _BB_DIR_BIN},
103 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
106 {"fdflush", fdflush_main, _BB_DIR_BIN},
109 {"find", find_main, _BB_DIR_USR_BIN},
112 {"free", free_main, _BB_DIR_USR_BIN},
114 #ifdef BB_FREERAMDISK
115 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
118 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
121 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
124 {"grep", grep_main, _BB_DIR_BIN},
127 {"gunzip", gunzip_main, _BB_DIR_BIN},
130 {"gzip", gzip_main, _BB_DIR_BIN},
133 {"halt", halt_main, _BB_DIR_SBIN},
136 {"head", head_main, _BB_DIR_BIN},
139 {"hostid", hostid_main, _BB_DIR_USR_BIN},
142 {"hostname", hostname_main, _BB_DIR_BIN},
145 {"id", id_main, _BB_DIR_USR_BIN},
148 {"init", init_main, _BB_DIR_SBIN},
151 {"insmod", insmod_main, _BB_DIR_SBIN},
154 {"kill", kill_main, _BB_DIR_BIN},
157 {"killall", kill_main, _BB_DIR_USR_BIN},
160 {"length", length_main, _BB_DIR_USR_BIN},
163 {"linuxrc", init_main, _BB_DIR_ROOT},
166 {"ln", ln_main, _BB_DIR_BIN},
169 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
172 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
175 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
178 {"logger", logger_main, _BB_DIR_USR_BIN},
181 {"logname", logname_main, _BB_DIR_USR_BIN},
184 {"ls", ls_main, _BB_DIR_BIN},
187 {"lsmod", lsmod_main, _BB_DIR_SBIN},
190 {"makedevs", makedevs_main, _BB_DIR_SBIN},
193 {"math", math_main, _BB_DIR_USR_BIN},
196 {"md5sum", md5sum_main, _BB_DIR_USR_BIN},
199 {"mkdir", mkdir_main, _BB_DIR_BIN},
202 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
205 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
208 {"mknod", mknod_main, _BB_DIR_BIN},
211 {"mkswap", mkswap_main, _BB_DIR_SBIN},
214 {"mktemp", mktemp_main, _BB_DIR_BIN},
217 {"nc", nc_main, _BB_DIR_USR_BIN},
220 {"more", more_main, _BB_DIR_BIN},
223 {"mount", mount_main, _BB_DIR_BIN},
226 {"mt", mt_main, _BB_DIR_BIN},
229 {"mv", cp_mv_main, _BB_DIR_BIN},
232 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
235 {"ping", ping_main, _BB_DIR_BIN},
238 {"poweroff", poweroff_main, _BB_DIR_SBIN},
241 {"printf", printf_main, _BB_DIR_USR_BIN},
244 {"ps", ps_main, _BB_DIR_BIN},
247 {"pwd", pwd_main, _BB_DIR_BIN},
250 {"reboot", reboot_main, _BB_DIR_SBIN},
253 {"rm", rm_main, _BB_DIR_BIN},
256 {"rmdir", rmdir_main, _BB_DIR_BIN},
259 {"rmmod", rmmod_main, _BB_DIR_SBIN},
262 {"sed", sed_main, _BB_DIR_BIN},
264 #ifdef BB_SETKEYCODES
265 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
268 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
271 {"sh", shell_main, _BB_DIR_BIN},
274 {"sleep", sleep_main, _BB_DIR_BIN},
277 {"sort", sort_main, _BB_DIR_BIN},
280 {"sync", sync_main, _BB_DIR_BIN},
283 {"syslogd", syslogd_main, _BB_DIR_SBIN},
286 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
289 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
292 {"tail", tail_main, _BB_DIR_USR_BIN},
295 {"tar", tar_main, _BB_DIR_BIN},
298 {"telnet", telnet_main, _BB_DIR_USR_BIN},
301 {"test", test_main, _BB_DIR_USR_BIN},
304 {"tee", tee_main, _BB_DIR_BIN},
307 {"touch", touch_main, _BB_DIR_USR_BIN},
310 {"tr", tr_main, _BB_DIR_USR_BIN},
313 {"true", true_main, _BB_DIR_BIN},
316 {"tty", tty_main, _BB_DIR_USR_BIN},
319 {"umount", umount_main, _BB_DIR_BIN},
322 {"uname", uname_main, _BB_DIR_BIN},
325 {"uniq", uniq_main, _BB_DIR_USR_BIN},
328 {"update", update_main, _BB_DIR_SBIN},
331 {"uptime", uptime_main, _BB_DIR_USR_BIN},
334 {"uuencode", uuencode_main, _BB_DIR_USR_BIN},
337 {"uudecode", uudecode_main, _BB_DIR_USR_BIN},
340 {"usleep", usleep_main, _BB_DIR_BIN},
343 {"wc", wc_main, _BB_DIR_USR_BIN},
346 {"which", which_main, _BB_DIR_USR_BIN},
349 {"whoami", whoami_main, _BB_DIR_USR_BIN},
352 {"yes", yes_main, _BB_DIR_USR_BIN},
355 {"zcat", gunzip_main, _BB_DIR_BIN},
358 {"[", test_main, _BB_DIR_USR_BIN},
365 int main(int argc, char **argv)
369 const struct BB_applet *a = applets;
371 for (s = name = argv[0]; *s != '\0';) {
378 while (a->name != 0) {
379 if (strcmp(name, a->name) == 0) {
380 exit(((*(a->main)) (argc, argv)));
384 return(busybox_main(argc, argv));
388 int busybox_main(int argc, char **argv)
395 if (been_there_done_that == 1 || argc < 1) {
396 const struct BB_applet *a = applets;
398 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
399 "Usage: busybox [function] [arguments]...\n"
400 " or: [function] [arguments]...\n\n"
401 "\tBusyBox is a multi-call binary that combines many common Unix\n"
402 "\tutilities into a single executable. Most people will create a\n"
403 "\tlink to busybox for each function they wish to use, and BusyBox\n"
404 "\twill act like whatever it was invoked as.\n"
405 "\nCurrently defined functions:\n", BB_VER, BB_BT);
407 while (a->name != 0) {
409 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
411 if (col > 60 && a->name != 0) {
412 fprintf(stderr, ",\n");
416 fprintf(stderr, "\n\n");
419 /* If we've already been here once, exit now */
420 been_there_done_that = 1;
421 return (main(argc, argv));
426 c-file-style: "linux"