blob: 07caa3446fbdfb17e77f327d852dcdb74cdfb4d7 [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
Erik Andersenbcd61772000-05-13 06:33:19 +000033const struct BB_applet applets[] = {
Eric Andersencc8ed391999-10-05 16:24:54 +000034
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 Andersen5e1189e2000-04-15 16:34:54 +000048 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
49#endif
50#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000051 {"chmod", 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 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
55#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 Andersen7ab9c7e2000-05-12 19:41:47 +000068#ifdef BB_CUT
69 {"cut", cut_main, _BB_DIR_USR_BIN},
70#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 Andersen5e1189e2000-04-15 16:34:54 +000095#ifdef BB_TRUE_FALSE
96 {"false", false_main, _BB_DIR_BIN},
97#endif
Erik Andersen298854f2000-03-23 01:09:18 +000098#ifdef BB_FBSET
Erik Andersend75af992000-03-16 08:09:09 +000099 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
Erik Andersen1c5b2581999-12-16 20:59:36 +0000100#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000101#ifdef BB_FDFLUSH
Erik Andersend75af992000-03-16 08:09:09 +0000102 {"fdflush", fdflush_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000103#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000104#ifdef BB_FIND
Erik Andersend75af992000-03-16 08:09:09 +0000105 {"find", find_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000106#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000107#ifdef BB_FREE
Erik Andersend75af992000-03-16 08:09:09 +0000108 {"free", free_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000109#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000110#ifdef BB_FREERAMDISK
Erik Andersend75af992000-03-16 08:09:09 +0000111 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
Erik Andersen64371702000-03-04 22:23:27 +0000112#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000113#ifdef BB_DEALLOCVT
Erik Andersend75af992000-03-16 08:09:09 +0000114 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000115#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000116#ifdef BB_FSCK_MINIX
Erik Andersend75af992000-03-16 08:09:09 +0000117 {"fsck.minix", fsck_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 Andersen5e1189e2000-04-15 16:34:54 +0000122#ifdef BB_GUNZIP
123 {"gunzip", gunzip_main, _BB_DIR_BIN},
124#endif
125#ifdef BB_GZIP
126 {"gzip", gzip_main, _BB_DIR_BIN},
127#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000128#ifdef BB_HALT
Erik Andersend75af992000-03-16 08:09:09 +0000129 {"halt", halt_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000130#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000131#ifdef BB_HEAD
Erik Andersend75af992000-03-16 08:09:09 +0000132 {"head", head_main, _BB_DIR_BIN},
John Beppu3157b1f1999-12-10 07:42:50 +0000133#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000134#ifdef BB_HOSTID
Erik Andersend75af992000-03-16 08:09:09 +0000135 {"hostid", hostid_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000136#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000137#ifdef BB_HOSTNAME
Erik Andersend75af992000-03-16 08:09:09 +0000138 {"hostname", hostname_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000139#endif
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000140#ifdef BB_ID
141 {"id", id_main, _BB_DIR_USR_BIN},
142#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000143#ifdef BB_INIT
Erik Andersend75af992000-03-16 08:09:09 +0000144 {"init", init_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000145#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000146#ifdef BB_INSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000147 {"insmod", insmod_main, _BB_DIR_SBIN},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000148#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000149#ifdef BB_KILL
Erik Andersend75af992000-03-16 08:09:09 +0000150 {"kill", kill_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000151#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000152#ifdef BB_KILLALL
Erik Andersend75af992000-03-16 08:09:09 +0000153 {"killall", kill_main, _BB_DIR_USR_BIN},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000154#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000155#ifdef BB_LENGTH
Erik Andersend75af992000-03-16 08:09:09 +0000156 {"length", length_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000157#endif
Erik Andersen9a8195c2000-04-18 23:32:10 +0000158#ifdef BB_LINUXRC
Erik Andersen5e1189e2000-04-15 16:34:54 +0000159 {"linuxrc", init_main, _BB_DIR_ROOT},
160#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000161#ifdef BB_LN
Erik Andersend75af992000-03-16 08:09:09 +0000162 {"ln", ln_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000163#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000164#ifdef BB_LOADACM
Erik Andersend75af992000-03-16 08:09:09 +0000165 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000166#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000167#ifdef BB_LOADFONT
Erik Andersend75af992000-03-16 08:09:09 +0000168 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000169#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000170#ifdef BB_LOADKMAP
Erik Andersend75af992000-03-16 08:09:09 +0000171 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000172#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000173#ifdef BB_LOGGER
174 {"logger", logger_main, _BB_DIR_USR_BIN},
175#endif
176#ifdef BB_LOGNAME
177 {"logname", logname_main, _BB_DIR_USR_BIN},
178#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000179#ifdef BB_LS
Erik Andersend75af992000-03-16 08:09:09 +0000180 {"ls", ls_main, _BB_DIR_BIN},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000181#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000182#ifdef BB_LSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000183 {"lsmod", lsmod_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000184#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000185#ifdef BB_MAKEDEVS
Erik Andersend75af992000-03-16 08:09:09 +0000186 {"makedevs", makedevs_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000187#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000188#ifdef BB_MATH
Erik Andersend75af992000-03-16 08:09:09 +0000189 {"math", math_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000190#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000191#ifdef BB_MKDIR
Erik Andersend75af992000-03-16 08:09:09 +0000192 {"mkdir", mkdir_main, _BB_DIR_BIN},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000193#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000194#ifdef BB_MKFIFO
Erik Andersend75af992000-03-16 08:09:09 +0000195 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
Eric Andersen19db07b1999-12-11 08:41:28 +0000196#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000197#ifdef BB_MKFS_MINIX
198 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
199#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000200#ifdef BB_MKNOD
Erik Andersend75af992000-03-16 08:09:09 +0000201 {"mknod", mknod_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000202#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000203#ifdef BB_MKSWAP
Erik Andersend75af992000-03-16 08:09:09 +0000204 {"mkswap", mkswap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000205#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000206#ifdef BB_MKTEMP
207 {"mktemp", mktemp_main, _BB_DIR_BIN},
208#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000209#ifdef BB_NC
210 {"nc", nc_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000211#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000212#ifdef BB_MORE
Erik Andersend75af992000-03-16 08:09:09 +0000213 {"more", more_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000214#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000215#ifdef BB_MOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000216 {"mount", mount_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000217#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000218#ifdef BB_MT
Erik Andersend75af992000-03-16 08:09:09 +0000219 {"mt", mt_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000220#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000221#ifdef BB_CP_MV
222 {"mv", cp_mv_main, _BB_DIR_BIN},
223#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000224#ifdef BB_NSLOOKUP
Erik Andersend75af992000-03-16 08:09:09 +0000225 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
John Beppub332e772000-01-29 12:59:01 +0000226#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000227#ifdef BB_PING
Erik Andersend75af992000-03-16 08:09:09 +0000228 {"ping", ping_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000229#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000230#ifdef BB_POWEROFF
Erik Andersend75af992000-03-16 08:09:09 +0000231 {"poweroff", poweroff_main, _BB_DIR_SBIN},
Eric Andersen2cb55071999-12-10 08:25:07 +0000232#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000233#ifdef BB_PRINTF
Erik Andersend75af992000-03-16 08:09:09 +0000234 {"printf", printf_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000235#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000236#ifdef BB_PS
Erik Andersend75af992000-03-16 08:09:09 +0000237 {"ps", ps_main, _BB_DIR_BIN},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000238#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000239#ifdef BB_PWD
Erik Andersend75af992000-03-16 08:09:09 +0000240 {"pwd", pwd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000241#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000242#ifdef BB_REBOOT
Erik Andersend75af992000-03-16 08:09:09 +0000243 {"reboot", reboot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000244#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000245#ifdef BB_RM
Erik Andersend75af992000-03-16 08:09:09 +0000246 {"rm", rm_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000247#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000248#ifdef BB_RMDIR
Erik Andersend75af992000-03-16 08:09:09 +0000249 {"rmdir", rmdir_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000250#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000251#ifdef BB_RMMOD
Erik Andersend75af992000-03-16 08:09:09 +0000252 {"rmmod", rmmod_main, _BB_DIR_SBIN},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000253#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000254#ifdef BB_SED
Erik Andersend75af992000-03-16 08:09:09 +0000255 {"sed", sed_main, _BB_DIR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000256#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000257#ifdef BB_SETKEYCODES
258 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000259#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000260#ifdef BB_SFDISK
Erik Andersend75af992000-03-16 08:09:09 +0000261 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
Eric Andersene77ae3a1999-10-19 20:03:34 +0000262#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000263#ifdef BB_SH
264 {"sh", shell_main, _BB_DIR_BIN},
265#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000266#ifdef BB_SLEEP
Erik Andersend75af992000-03-16 08:09:09 +0000267 {"sleep", sleep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000268#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000269#ifdef BB_SORT
Erik Andersend75af992000-03-16 08:09:09 +0000270 {"sort", sort_main, _BB_DIR_BIN},
John Beppu019513a1999-12-22 17:57:31 +0000271#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000272#ifdef BB_SYNC
Erik Andersend75af992000-03-16 08:09:09 +0000273 {"sync", sync_main, _BB_DIR_BIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000274#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000275#ifdef BB_SYSLOGD
Erik Andersend75af992000-03-16 08:09:09 +0000276 {"syslogd", syslogd_main, _BB_DIR_SBIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000277#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000278#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000279 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
280#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000281#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000282 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000283#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000284#ifdef BB_TAIL
Erik Andersend75af992000-03-16 08:09:09 +0000285 {"tail", tail_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000286#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000287#ifdef BB_TAR
Erik Andersend75af992000-03-16 08:09:09 +0000288 {"tar", tar_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000289#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000290#ifdef BB_TELNET
Erik Andersend75af992000-03-16 08:09:09 +0000291 {"telnet", telnet_main, _BB_DIR_USR_BIN},
292#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000293#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000294 {"test", test_main, _BB_DIR_USR_BIN},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000295#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000296#ifdef BB_TEE
Erik Andersend75af992000-03-16 08:09:09 +0000297 {"tee", tee_main, _BB_DIR_BIN},
John Beppu059f1521999-12-10 05:27:16 +0000298#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000299#ifdef BB_TOUCH
Erik Andersend75af992000-03-16 08:09:09 +0000300 {"touch", touch_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000301#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000302#ifdef BB_TR
Erik Andersend75af992000-03-16 08:09:09 +0000303 {"tr", tr_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +0000304#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000305#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000306 {"true", true_main, _BB_DIR_BIN},
307#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000308#ifdef BB_TTY
Erik Andersend75af992000-03-16 08:09:09 +0000309 {"tty", tty_main, _BB_DIR_USR_BIN},
Erik Andersen05df2392000-01-13 04:43:48 +0000310#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000311#ifdef BB_UMOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000312 {"umount", umount_main, _BB_DIR_BIN},
Erik Andersen66be5e72000-03-05 07:52:05 +0000313#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000314#ifdef BB_UNAME
Erik Andersend75af992000-03-16 08:09:09 +0000315 {"uname", uname_main, _BB_DIR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000316#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000317#ifdef BB_UNIQ
Erik Andersena6c75222000-04-18 00:00:52 +0000318 {"uniq", uniq_main, _BB_DIR_USR_BIN},
John Beppuabb47722000-01-06 00:48:21 +0000319#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000320#ifdef BB_UPDATE
Erik Andersend75af992000-03-16 08:09:09 +0000321 {"update", update_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000322#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000323#ifdef BB_UPTIME
324 {"uptime", uptime_main, _BB_DIR_USR_BIN},
325#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000326#ifdef BB_USLEEP
327 {"usleep", usleep_main, _BB_DIR_BIN},
328#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000329#ifdef BB_WC
Erik Andersend75af992000-03-16 08:09:09 +0000330 {"wc", wc_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000331#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000332#ifdef BB_WHOAMI
Erik Andersend75af992000-03-16 08:09:09 +0000333 {"whoami", whoami_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000334#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000335#ifdef BB_YES
Erik Andersend75af992000-03-16 08:09:09 +0000336 {"yes", yes_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000337#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000338#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000339 {"zcat", gunzip_main, _BB_DIR_BIN},
340#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000341#ifdef BB_TEST
342 {"[", test_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000343#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000344 {0}
Eric Andersencc8ed391999-10-05 16:24:54 +0000345};
346
Erik Andersen05df2392000-01-13 04:43:48 +0000347
348
Eric Andersencc8ed391999-10-05 16:24:54 +0000349int main(int argc, char **argv)
350{
Erik Andersend75af992000-03-16 08:09:09 +0000351 char *s;
352 char *name;
Erik Andersenbcd61772000-05-13 06:33:19 +0000353 const struct BB_applet *a = applets;
Eric Andersencc8ed391999-10-05 16:24:54 +0000354
Erik Andersend75af992000-03-16 08:09:09 +0000355 for (s = name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000356 if (*s++ == '/')
357 name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000358 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000359
Erik Andersen029011b2000-03-04 21:19:32 +0000360 *argv = name;
361
Erik Andersene49d5ec2000-02-08 19:58:47 +0000362 while (a->name != 0) {
363 if (strcmp(name, a->name) == 0) {
364 int status;
365
366 status = ((*(a->main)) (argc, argv));
367 if (status < 0) {
368 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
369 }
370 fprintf(stderr, "\n");
371 exit(status);
372 }
373 a++;
374 }
375 exit(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000376}
377
378
379int busybox_main(int argc, char **argv)
380{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000381 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000382
Erik Andersene49d5ec2000-02-08 19:58:47 +0000383 argc--;
384 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000385
Erik Andersene49d5ec2000-02-08 19:58:47 +0000386 if (been_there_done_that == 1 || argc < 1) {
Erik Andersenbcd61772000-05-13 06:33:19 +0000387 const struct BB_applet *a = applets;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000388
389 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
390 BB_VER, BB_BT);
391 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
392 fprintf(stderr, " or: [function] [arguments]...\n\n");
393 fprintf(stderr,
John Beppub4f86062000-04-13 03:36:01 +0000394 "\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");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000398 fprintf(stderr, "\nCurrently defined functions:\n");
399
400 while (a->name != 0) {
401 col +=
402 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
403 (a++)->name);
404 if (col > 60 && a->name != 0) {
405 fprintf(stderr, ",\n");
406 col = 0;
407 }
408 }
409 fprintf(stderr, "\n\n");
410 exit(-1);
411 } else {
412 /* If we've already been here once, exit now */
413 been_there_done_that = 1;
414 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000415 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000416}
Erik Andersen029011b2000-03-04 21:19:32 +0000417
418/*
419Local Variables:
420c-file-style: "linux"
421c-basic-offset: 4
422tab-width: 4
423End:
424*/