blob: b65b13e65598575cdb93aa298decc2988a7222a9 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersencc8ed391999-10-05 16:24:54 +00002#include "internal.h"
3#include <stdio.h>
4#include <string.h>
5#include <errno.h>
6
7static int been_there_done_that = 0;
8
Erik Andersen31638212000-01-15 22:28:50 +00009/* 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
14 */
Erik Andersen05df2392000-01-13 04:43:48 +000015#if 0
Erik Andersene49d5ec2000-02-08 19:58:47 +000016void exit(int status) __attribute__ ((noreturn));
17void exit(int status)
18{
19 _exit(status);
20};
21void abort(void) __attribute__ ((__noreturn__));
22void abort(void)
23{
24 _exit(0);
25};
26int atexit(void (*__func) (void))
27{
28 _exit(0);
29};
Erik Andersen05df2392000-01-13 04:43:48 +000030void *__libc_stack_end;
31#endif
32
Eric Andersencc8ed391999-10-05 16:24:54 +000033static const struct Applet applets[] = {
34
Erik Andersen298854f2000-03-23 01:09:18 +000035#ifdef BB_BASENAME
Erik Andersend75af992000-03-16 08:09:09 +000036 {"basename", basename_main, _BB_DIR_USR_BIN},
Erik Andersene2729152000-02-18 21:34:17 +000037#endif
Erik Andersen298854f2000-03-23 01:09:18 +000038#ifdef BB_BUSYBOX
Erik Andersend75af992000-03-16 08:09:09 +000039 {"busybox", busybox_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000040#endif
Erik Andersen298854f2000-03-23 01:09:18 +000041#ifdef BB_BLOCK_DEVICE
Erik Andersend75af992000-03-16 08:09:09 +000042 {"block_device", block_device_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000043#endif
Erik Andersen298854f2000-03-23 01:09:18 +000044#ifdef BB_CAT
Erik Andersend75af992000-03-16 08:09:09 +000045 {"cat", cat_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000046#endif
Erik Andersen298854f2000-03-23 01:09:18 +000047#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000048 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
49#endif
Erik Andersen298854f2000-03-23 01:09:18 +000050#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000051 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
52#endif
Erik Andersen298854f2000-03-23 01:09:18 +000053#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000054 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000055#endif
Erik Andersen298854f2000-03-23 01:09:18 +000056#ifdef BB_CHROOT
Erik Andersend75af992000-03-16 08:09:09 +000057 {"chroot", chroot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000058#endif
Erik Andersen298854f2000-03-23 01:09:18 +000059#ifdef BB_CLEAR
Erik Andersend75af992000-03-16 08:09:09 +000060 {"clear", clear_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000061#endif
Erik Andersen298854f2000-03-23 01:09:18 +000062#ifdef BB_CHVT
Erik Andersend75af992000-03-16 08:09:09 +000063 {"chvt", chvt_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +000064#endif
Erik Andersen298854f2000-03-23 01:09:18 +000065#ifdef BB_CP_MV
Erik Andersend75af992000-03-16 08:09:09 +000066 {"cp", cp_mv_main, _BB_DIR_BIN},
67#endif
Erik Andersen298854f2000-03-23 01:09:18 +000068#ifdef BB_CP_MV
Erik Andersend75af992000-03-16 08:09:09 +000069 {"mv", cp_mv_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000070#endif
Erik Andersen298854f2000-03-23 01:09:18 +000071#ifdef BB_DATE
Erik Andersend75af992000-03-16 08:09:09 +000072 {"date", date_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000073#endif
Erik Andersen298854f2000-03-23 01:09:18 +000074#ifdef BB_DD
Erik Andersend75af992000-03-16 08:09:09 +000075 {"dd", dd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000076#endif
Erik Andersen298854f2000-03-23 01:09:18 +000077#ifdef BB_DF
Erik Andersend75af992000-03-16 08:09:09 +000078 {"df", df_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000079#endif
Erik Andersen298854f2000-03-23 01:09:18 +000080#ifdef BB_DIRNAME
Erik Andersend75af992000-03-16 08:09:09 +000081 {"dirname", dirname_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +000082#endif
Erik Andersen298854f2000-03-23 01:09:18 +000083#ifdef BB_DMESG
Erik Andersend75af992000-03-16 08:09:09 +000084 {"dmesg", dmesg_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000085#endif
Erik Andersen298854f2000-03-23 01:09:18 +000086#ifdef BB_DU
Erik Andersend75af992000-03-16 08:09:09 +000087 {"du", du_main, _BB_DIR_BIN},
John Beppu7a986061999-12-09 18:29:29 +000088#endif
Erik Andersen298854f2000-03-23 01:09:18 +000089#ifdef BB_DUTMP
Erik Andersend75af992000-03-16 08:09:09 +000090 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
91#endif
Erik Andersen298854f2000-03-23 01:09:18 +000092#ifdef BB_ECHO
Erik Andersend75af992000-03-16 08:09:09 +000093 {"echo", echo_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000094#endif
Erik Andersen298854f2000-03-23 01:09:18 +000095#ifdef BB_FBSET
Erik Andersend75af992000-03-16 08:09:09 +000096 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
Erik Andersen1c5b2581999-12-16 20:59:36 +000097#endif
Erik Andersen298854f2000-03-23 01:09:18 +000098#ifdef BB_FDFLUSH
Erik Andersend75af992000-03-16 08:09:09 +000099 {"fdflush", fdflush_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000100#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000101#ifdef BB_FIND
Erik Andersend75af992000-03-16 08:09:09 +0000102 {"find", find_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000103#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000104#ifdef BB_FREE
Erik Andersend75af992000-03-16 08:09:09 +0000105 {"free", free_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000106#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000107#ifdef BB_FREERAMDISK
Erik Andersend75af992000-03-16 08:09:09 +0000108 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
Erik Andersen64371702000-03-04 22:23:27 +0000109#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000110#ifdef BB_DEALLOCVT
Erik Andersend75af992000-03-16 08:09:09 +0000111 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000112#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000113#ifdef BB_FSCK_MINIX
Erik Andersend75af992000-03-16 08:09:09 +0000114 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
Eric Andersene494fdd1999-10-19 20:23:03 +0000115#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000116#ifdef BB_MKFS_MINIX
Erik Andersend75af992000-03-16 08:09:09 +0000117 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
Eric Andersene494fdd1999-10-19 20:23:03 +0000118#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000119#ifdef BB_GREP
Erik Andersend75af992000-03-16 08:09:09 +0000120 {"grep", grep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000121#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000122#ifdef BB_HALT
Erik Andersend75af992000-03-16 08:09:09 +0000123 {"halt", halt_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000124#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000125#ifdef BB_HEAD
Erik Andersend75af992000-03-16 08:09:09 +0000126 {"head", head_main, _BB_DIR_BIN},
John Beppu3157b1f1999-12-10 07:42:50 +0000127#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000128#ifdef BB_HOSTID
Erik Andersend75af992000-03-16 08:09:09 +0000129 {"hostid", hostid_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000130#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000131#ifdef BB_HOSTNAME
Erik Andersend75af992000-03-16 08:09:09 +0000132 {"hostname", hostname_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000133#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000134#ifdef BB_INIT
Erik Andersend75af992000-03-16 08:09:09 +0000135 {"init", init_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000136#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000137#ifdef BB_INSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000138 {"insmod", insmod_main, _BB_DIR_SBIN},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000139#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000140#ifdef BB_FEATURE_LINUXRC //
Erik Andersend75af992000-03-16 08:09:09 +0000141 {"linuxrc", init_main, _BB_DIR_ROOT},
Eric Andersen6a76e651999-11-19 05:31:45 +0000142#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000143#ifdef BB_KILL
Erik Andersend75af992000-03-16 08:09:09 +0000144 {"kill", kill_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000145#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000146#ifdef BB_KILLALL
Erik Andersend75af992000-03-16 08:09:09 +0000147 {"killall", kill_main, _BB_DIR_USR_BIN},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000148#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000149#ifdef BB_LENGTH
Erik Andersend75af992000-03-16 08:09:09 +0000150 {"length", length_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000151#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000152#ifdef BB_LN
Erik Andersend75af992000-03-16 08:09:09 +0000153 {"ln", ln_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000154#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000155#ifdef BB_LOADACM
Erik Andersend75af992000-03-16 08:09:09 +0000156 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000157#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000158#ifdef BB_LOADFONT
Erik Andersend75af992000-03-16 08:09:09 +0000159 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000160#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000161#ifdef BB_LOADKMAP
Erik Andersend75af992000-03-16 08:09:09 +0000162 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000163#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000164#ifdef BB_LS
Erik Andersend75af992000-03-16 08:09:09 +0000165 {"ls", ls_main, _BB_DIR_BIN},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000166#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000167#ifdef BB_LSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000168 {"lsmod", lsmod_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000169#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000170#ifdef BB_MAKEDEVS
Erik Andersend75af992000-03-16 08:09:09 +0000171 {"makedevs", makedevs_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000172#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000173#ifdef BB_MATH
Erik Andersend75af992000-03-16 08:09:09 +0000174 {"math", math_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000175#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000176#ifdef BB_MKDIR
Erik Andersend75af992000-03-16 08:09:09 +0000177 {"mkdir", mkdir_main, _BB_DIR_BIN},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000178#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000179#ifdef BB_MKFIFO
Erik Andersend75af992000-03-16 08:09:09 +0000180 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
Eric Andersen19db07b1999-12-11 08:41:28 +0000181#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000182#ifdef BB_MKNOD
Erik Andersend75af992000-03-16 08:09:09 +0000183 {"mknod", mknod_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000184#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000185#ifdef BB_MKSWAP
Erik Andersend75af992000-03-16 08:09:09 +0000186 {"mkswap", mkswap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000187#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000188#ifdef BB_MNC
Erik Andersend75af992000-03-16 08:09:09 +0000189 {"mnc", mnc_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000190#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000191#ifdef BB_MORE
Erik Andersend75af992000-03-16 08:09:09 +0000192 {"more", more_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000193#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000194#ifdef BB_MOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000195 {"mount", mount_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000196#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000197#ifdef BB_MT
Erik Andersend75af992000-03-16 08:09:09 +0000198 {"mt", mt_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000199#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000200#ifdef BB_NSLOOKUP
Erik Andersend75af992000-03-16 08:09:09 +0000201 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
John Beppub332e772000-01-29 12:59:01 +0000202#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000203#ifdef BB_PING
Erik Andersend75af992000-03-16 08:09:09 +0000204 {"ping", ping_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000205#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000206#ifdef BB_POWEROFF
Erik Andersend75af992000-03-16 08:09:09 +0000207 {"poweroff", poweroff_main, _BB_DIR_SBIN},
Eric Andersen2cb55071999-12-10 08:25:07 +0000208#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000209#ifdef BB_PRINTF
Erik Andersend75af992000-03-16 08:09:09 +0000210 {"printf", printf_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000211#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000212#ifdef BB_PS
Erik Andersend75af992000-03-16 08:09:09 +0000213 {"ps", ps_main, _BB_DIR_BIN},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000214#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000215#ifdef BB_PWD
Erik Andersend75af992000-03-16 08:09:09 +0000216 {"pwd", pwd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000217#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000218#ifdef BB_REBOOT
Erik Andersend75af992000-03-16 08:09:09 +0000219 {"reboot", reboot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000220#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000221#ifdef BB_RM
Erik Andersend75af992000-03-16 08:09:09 +0000222 {"rm", rm_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000223#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000224#ifdef BB_RMDIR
Erik Andersend75af992000-03-16 08:09:09 +0000225 {"rmdir", rmdir_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000226#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000227#ifdef BB_RMMOD
Erik Andersend75af992000-03-16 08:09:09 +0000228 {"rmmod", rmmod_main, _BB_DIR_SBIN},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000229#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000230#ifdef BB_SED
Erik Andersend75af992000-03-16 08:09:09 +0000231 {"sed", sed_main, _BB_DIR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000232#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000233#ifdef BB_SH
Erik Andersend75af992000-03-16 08:09:09 +0000234 {"sh", shell_main, _BB_DIR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000235#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000236#ifdef BB_SFDISK
Erik Andersend75af992000-03-16 08:09:09 +0000237 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
Eric Andersene77ae3a1999-10-19 20:03:34 +0000238#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000239#ifdef BB_SLEEP
Erik Andersend75af992000-03-16 08:09:09 +0000240 {"sleep", sleep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000241#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000242#ifdef BB_SORT
Erik Andersend75af992000-03-16 08:09:09 +0000243 {"sort", sort_main, _BB_DIR_BIN},
John Beppu019513a1999-12-22 17:57:31 +0000244#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000245#ifdef BB_SYNC
Erik Andersend75af992000-03-16 08:09:09 +0000246 {"sync", sync_main, _BB_DIR_BIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000247#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000248#ifdef BB_SYSLOGD
Erik Andersend75af992000-03-16 08:09:09 +0000249 {"syslogd", syslogd_main, _BB_DIR_SBIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000250#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000251#ifdef BB_LOGGER
Erik Andersend75af992000-03-16 08:09:09 +0000252 {"logger", logger_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000253#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000254#ifdef BB_LOGNAME
Erik Andersend75af992000-03-16 08:09:09 +0000255 {"logname", logname_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000256#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000257#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000258 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
259#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000260#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000261 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000262#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000263#ifdef BB_TAIL
Erik Andersend75af992000-03-16 08:09:09 +0000264 {"tail", tail_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000265#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000266#ifdef BB_TAR
Erik Andersend75af992000-03-16 08:09:09 +0000267 {"tar", tar_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000268#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000269#ifdef BB_TELNET
Erik Andersend75af992000-03-16 08:09:09 +0000270 {"telnet", telnet_main, _BB_DIR_USR_BIN},
271#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000272#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000273 {"[", test_main, _BB_DIR_USR_BIN},
274#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000275#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000276 {"test", test_main, _BB_DIR_USR_BIN},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000277#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000278#ifdef BB_TEE
Erik Andersend75af992000-03-16 08:09:09 +0000279 {"tee", tee_main, _BB_DIR_BIN},
John Beppu059f1521999-12-10 05:27:16 +0000280#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000281#ifdef BB_TOUCH
Erik Andersend75af992000-03-16 08:09:09 +0000282 {"touch", touch_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000283#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000284#ifdef BB_TR
Erik Andersend75af992000-03-16 08:09:09 +0000285 {"tr", tr_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +0000286#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000287#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000288 {"true", true_main, _BB_DIR_BIN},
289#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000290#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000291 {"false", false_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000292#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000293#ifdef BB_TTY
Erik Andersend75af992000-03-16 08:09:09 +0000294 {"tty", tty_main, _BB_DIR_USR_BIN},
Erik Andersen05df2392000-01-13 04:43:48 +0000295#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000296#ifdef BB_UMOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000297 {"umount", umount_main, _BB_DIR_BIN},
Erik Andersen66be5e72000-03-05 07:52:05 +0000298#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000299#ifdef BB_UNAME
Erik Andersend75af992000-03-16 08:09:09 +0000300 {"uname", uname_main, _BB_DIR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000301#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000302#ifdef BB_UPTIME
Erik Andersend75af992000-03-16 08:09:09 +0000303 {"uptime", uptime_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000304#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000305#ifdef BB_UNIQ
Erik Andersend75af992000-03-16 08:09:09 +0000306 {"uniq", uniq_main, _BB_DIR_BIN},
John Beppuabb47722000-01-06 00:48:21 +0000307#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000308#ifdef BB_UPDATE
Erik Andersend75af992000-03-16 08:09:09 +0000309 {"update", update_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000310#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000311#ifdef BB_USLEEP
312 {"usleep", usleep_main, _BB_DIR_BIN},
313#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000314#ifdef BB_WC
Erik Andersend75af992000-03-16 08:09:09 +0000315 {"wc", wc_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000316#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000317#ifdef BB_WHOAMI
Erik Andersend75af992000-03-16 08:09:09 +0000318 {"whoami", whoami_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000319#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000320#ifdef BB_YES
Erik Andersend75af992000-03-16 08:09:09 +0000321 {"yes", yes_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000322#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000323#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000324 {"zcat", gunzip_main, _BB_DIR_BIN},
325#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000326#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000327 {"gunzip", gunzip_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000328#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000329#ifdef BB_GZIP
Erik Andersend75af992000-03-16 08:09:09 +0000330 {"gzip", gzip_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000331#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000332 {0}
Eric Andersencc8ed391999-10-05 16:24:54 +0000333};
334
Erik Andersen05df2392000-01-13 04:43:48 +0000335
336
Eric Andersencc8ed391999-10-05 16:24:54 +0000337int main(int argc, char **argv)
338{
Erik Andersend75af992000-03-16 08:09:09 +0000339 char *s;
340 char *name;
Erik Andersen029011b2000-03-04 21:19:32 +0000341 const struct Applet *a = applets;
Eric Andersencc8ed391999-10-05 16:24:54 +0000342
Erik Andersend75af992000-03-16 08:09:09 +0000343 for (s = name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000344 if (*s++ == '/')
345 name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000346 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000347
Erik Andersen029011b2000-03-04 21:19:32 +0000348 *argv = name;
349
Erik Andersene49d5ec2000-02-08 19:58:47 +0000350 while (a->name != 0) {
351 if (strcmp(name, a->name) == 0) {
352 int status;
353
354 status = ((*(a->main)) (argc, argv));
355 if (status < 0) {
356 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
357 }
358 fprintf(stderr, "\n");
359 exit(status);
360 }
361 a++;
362 }
363 exit(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000364}
365
366
367int busybox_main(int argc, char **argv)
368{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000369 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000370
Erik Andersene49d5ec2000-02-08 19:58:47 +0000371 argc--;
372 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000373
Erik Andersene49d5ec2000-02-08 19:58:47 +0000374 if (been_there_done_that == 1 || argc < 1) {
375 const struct Applet *a = applets;
376
377 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
378 BB_VER, BB_BT);
379 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
380 fprintf(stderr, " or: [function] [arguments]...\n\n");
381 fprintf(stderr,
Erik Andersen61677fe2000-04-13 01:18:56 +0000382 "\tBusyBox is a multi-call binary that combines many common Unix utilities into a\n"
383 "\tsingle executable. Most people will create a link to busybox for each function\n"
384 "\tthey wish to use, and BusyBox will act like whatever it was invoked as.\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000385 fprintf(stderr, "\nCurrently defined functions:\n");
386
387 while (a->name != 0) {
388 col +=
389 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
390 (a++)->name);
391 if (col > 60 && a->name != 0) {
392 fprintf(stderr, ",\n");
393 col = 0;
394 }
395 }
396 fprintf(stderr, "\n\n");
397 exit(-1);
398 } else {
399 /* If we've already been here once, exit now */
400 been_there_done_that = 1;
401 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000402 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000403}
Erik Andersen029011b2000-03-04 21:19:32 +0000404
405/*
406Local Variables:
407c-file-style: "linux"
408c-basic-offset: 4
409tab-width: 4
410End:
411*/