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