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 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
50 #ifdef BB_CHMOD_CHOWN_CHGRP
51 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
53 #ifdef BB_CHMOD_CHOWN_CHGRP
54 {"chgrp", 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 {"mv", cp_mv_main, _BB_DIR_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 {"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 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
120 {"grep", grep_main, _BB_DIR_BIN},
123 {"halt", halt_main, _BB_DIR_SBIN},
126 {"head", head_main, _BB_DIR_BIN},
129 {"hostid", hostid_main, _BB_DIR_USR_BIN},
132 {"hostname", hostname_main, _BB_DIR_BIN},
135 {"init", init_main, _BB_DIR_SBIN},
138 {"insmod", insmod_main, _BB_DIR_SBIN},
140 #ifdef BB_FEATURE_LINUXRC //
141 {"linuxrc", init_main, _BB_DIR_ROOT},
144 {"kill", kill_main, _BB_DIR_BIN},
147 {"killall", kill_main, _BB_DIR_USR_BIN},
150 {"length", length_main, _BB_DIR_USR_BIN},
153 {"ln", ln_main, _BB_DIR_BIN},
156 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
159 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
162 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
165 {"ls", ls_main, _BB_DIR_BIN},
168 {"lsmod", lsmod_main, _BB_DIR_SBIN},
171 {"makedevs", makedevs_main, _BB_DIR_SBIN},
174 {"math", math_main, _BB_DIR_USR_BIN},
177 {"mkdir", mkdir_main, _BB_DIR_BIN},
180 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
183 {"mknod", mknod_main, _BB_DIR_BIN},
186 {"mkswap", mkswap_main, _BB_DIR_SBIN},
189 {"mnc", mnc_main, _BB_DIR_USR_BIN},
192 {"more", more_main, _BB_DIR_BIN},
195 {"mount", mount_main, _BB_DIR_BIN},
198 {"mt", mt_main, _BB_DIR_BIN},
201 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
204 {"ping", ping_main, _BB_DIR_BIN},
207 {"poweroff", poweroff_main, _BB_DIR_SBIN},
210 {"printf", printf_main, _BB_DIR_USR_BIN},
213 {"ps", ps_main, _BB_DIR_BIN},
216 {"pwd", pwd_main, _BB_DIR_BIN},
219 {"reboot", reboot_main, _BB_DIR_SBIN},
222 {"rm", rm_main, _BB_DIR_BIN},
225 {"rmdir", rmdir_main, _BB_DIR_BIN},
228 {"rmmod", rmmod_main, _BB_DIR_SBIN},
231 {"sed", sed_main, _BB_DIR_BIN},
234 {"sh", shell_main, _BB_DIR_BIN},
237 {"fdisk", sfdisk_main, _BB_DIR_SBIN},
240 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
243 {"sleep", sleep_main, _BB_DIR_BIN},
246 {"sort", sort_main, _BB_DIR_BIN},
249 {"sync", sync_main, _BB_DIR_BIN},
252 {"syslogd", syslogd_main, _BB_DIR_SBIN},
255 {"logger", logger_main, _BB_DIR_USR_BIN},
258 {"logname", logname_main, _BB_DIR_USR_BIN},
261 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
264 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
267 {"tail", tail_main, _BB_DIR_USR_BIN},
270 {"tar", tar_main, _BB_DIR_BIN},
273 {"telnet", telnet_main, _BB_DIR_USR_BIN},
276 {"[", test_main, _BB_DIR_USR_BIN},
279 {"test", test_main, _BB_DIR_USR_BIN},
282 {"tee", tee_main, _BB_DIR_BIN},
285 {"touch", touch_main, _BB_DIR_USR_BIN},
288 {"tr", tr_main, _BB_DIR_USR_BIN},
291 {"true", true_main, _BB_DIR_BIN},
294 {"false", false_main, _BB_DIR_BIN},
297 {"tty", tty_main, _BB_DIR_USR_BIN},
300 {"umount", umount_main, _BB_DIR_BIN},
303 {"uname", uname_main, _BB_DIR_BIN},
306 {"uptime", uptime_main, _BB_DIR_USR_BIN},
309 {"uniq", uniq_main, _BB_DIR_BIN},
312 {"update", update_main, _BB_DIR_SBIN},
315 {"wc", wc_main, _BB_DIR_USR_BIN},
318 {"whoami", whoami_main, _BB_DIR_USR_BIN},
321 {"yes", yes_main, _BB_DIR_USR_BIN},
324 {"zcat", gunzip_main, _BB_DIR_BIN},
327 {"gunzip", gunzip_main, _BB_DIR_BIN},
330 {"gzip", gzip_main, _BB_DIR_BIN},
337 int main(int argc, char **argv)
341 const struct Applet *a = applets;
343 for (s = name = argv[0]; *s != '\0';) {
350 while (a->name != 0) {
351 if (strcmp(name, a->name) == 0) {
354 status = ((*(a->main)) (argc, argv));
356 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
358 fprintf(stderr, "\n");
363 exit(busybox_main(argc, argv));
367 int busybox_main(int argc, char **argv)
374 if (been_there_done_that == 1 || argc < 1) {
375 const struct Applet *a = applets;
377 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
379 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
380 fprintf(stderr, " or: [function] [arguments]...\n\n");
382 "\tMost people will create a link to busybox for each\n"
383 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
384 fprintf(stderr, "\nCurrently defined functions:\n");
386 while (a->name != 0) {
388 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
390 if (col > 60 && a->name != 0) {
391 fprintf(stderr, ",\n");
395 fprintf(stderr, "\n\n");
398 /* If we've already been here once, exit now */
399 been_there_done_that = 1;
400 return (main(argc, argv));
406 c-file-style: "linux"