blob: 9a48f496146cb24390fe956df7374099d4259a30 [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 {"fdisk", sfdisk_main, _BB_DIR_SBIN},
Erik Andersen298854f2000-03-23 01:09:18 +0000238#ifdef BB_SFDISK
Erik Andersend75af992000-03-16 08:09:09 +0000239#endif
240 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
Eric Andersene77ae3a1999-10-19 20:03:34 +0000241#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000242#ifdef BB_SLEEP
Erik Andersend75af992000-03-16 08:09:09 +0000243 {"sleep", sleep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000244#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000245#ifdef BB_SORT
Erik Andersend75af992000-03-16 08:09:09 +0000246 {"sort", sort_main, _BB_DIR_BIN},
John Beppu019513a1999-12-22 17:57:31 +0000247#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000248#ifdef BB_SYNC
Erik Andersend75af992000-03-16 08:09:09 +0000249 {"sync", sync_main, _BB_DIR_BIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000250#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000251#ifdef BB_SYSLOGD
Erik Andersend75af992000-03-16 08:09:09 +0000252 {"syslogd", syslogd_main, _BB_DIR_SBIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000253#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000254#ifdef BB_LOGGER
Erik Andersend75af992000-03-16 08:09:09 +0000255 {"logger", logger_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000256#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000257#ifdef BB_LOGNAME
Erik Andersend75af992000-03-16 08:09:09 +0000258 {"logname", logname_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000259#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000260#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000261 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
262#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000263#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000264 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000265#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000266#ifdef BB_TAIL
Erik Andersend75af992000-03-16 08:09:09 +0000267 {"tail", tail_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000268#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000269#ifdef BB_TAR
Erik Andersend75af992000-03-16 08:09:09 +0000270 {"tar", tar_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000271#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000272#ifdef BB_TELNET
Erik Andersend75af992000-03-16 08:09:09 +0000273 {"telnet", telnet_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_main, _BB_DIR_USR_BIN},
277#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000278#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000279 {"test", test_main, _BB_DIR_USR_BIN},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000280#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000281#ifdef BB_TEE
Erik Andersend75af992000-03-16 08:09:09 +0000282 {"tee", tee_main, _BB_DIR_BIN},
John Beppu059f1521999-12-10 05:27:16 +0000283#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000284#ifdef BB_TOUCH
Erik Andersend75af992000-03-16 08:09:09 +0000285 {"touch", touch_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000286#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000287#ifdef BB_TR
Erik Andersend75af992000-03-16 08:09:09 +0000288 {"tr", tr_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +0000289#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000290#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000291 {"true", true_main, _BB_DIR_BIN},
292#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000293#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000294 {"false", false_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000295#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000296#ifdef BB_TTY
Erik Andersend75af992000-03-16 08:09:09 +0000297 {"tty", tty_main, _BB_DIR_USR_BIN},
Erik Andersen05df2392000-01-13 04:43:48 +0000298#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000299#ifdef BB_UMOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000300 {"umount", umount_main, _BB_DIR_BIN},
Erik Andersen66be5e72000-03-05 07:52:05 +0000301#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000302#ifdef BB_UNAME
Erik Andersend75af992000-03-16 08:09:09 +0000303 {"uname", uname_main, _BB_DIR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000304#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000305#ifdef BB_UPTIME
Erik Andersend75af992000-03-16 08:09:09 +0000306 {"uptime", uptime_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000307#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000308#ifdef BB_UNIQ
Erik Andersend75af992000-03-16 08:09:09 +0000309 {"uniq", uniq_main, _BB_DIR_BIN},
John Beppuabb47722000-01-06 00:48:21 +0000310#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000311#ifdef BB_UPDATE
Erik Andersend75af992000-03-16 08:09:09 +0000312 {"update", update_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000313#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000314#ifdef BB_USLEEP
315 {"usleep", usleep_main, _BB_DIR_BIN},
316#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000317#ifdef BB_WC
Erik Andersend75af992000-03-16 08:09:09 +0000318 {"wc", wc_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000319#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000320#ifdef BB_WHOAMI
Erik Andersend75af992000-03-16 08:09:09 +0000321 {"whoami", whoami_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000322#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000323#ifdef BB_YES
Erik Andersend75af992000-03-16 08:09:09 +0000324 {"yes", yes_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000325#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000326#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000327 {"zcat", gunzip_main, _BB_DIR_BIN},
328#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000329#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000330 {"gunzip", gunzip_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000331#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000332#ifdef BB_GZIP
Erik Andersend75af992000-03-16 08:09:09 +0000333 {"gzip", gzip_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000334#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000335 {0}
Eric Andersencc8ed391999-10-05 16:24:54 +0000336};
337
Erik Andersen05df2392000-01-13 04:43:48 +0000338
339
Eric Andersencc8ed391999-10-05 16:24:54 +0000340int main(int argc, char **argv)
341{
Erik Andersend75af992000-03-16 08:09:09 +0000342 char *s;
343 char *name;
Erik Andersen029011b2000-03-04 21:19:32 +0000344 const struct Applet *a = applets;
Eric Andersencc8ed391999-10-05 16:24:54 +0000345
Erik Andersend75af992000-03-16 08:09:09 +0000346 for (s = name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000347 if (*s++ == '/')
348 name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000349 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000350
Erik Andersen029011b2000-03-04 21:19:32 +0000351 *argv = name;
352
Erik Andersene49d5ec2000-02-08 19:58:47 +0000353 while (a->name != 0) {
354 if (strcmp(name, a->name) == 0) {
355 int status;
356
357 status = ((*(a->main)) (argc, argv));
358 if (status < 0) {
359 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
360 }
361 fprintf(stderr, "\n");
362 exit(status);
363 }
364 a++;
365 }
366 exit(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000367}
368
369
370int busybox_main(int argc, char **argv)
371{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000372 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000373
Erik Andersene49d5ec2000-02-08 19:58:47 +0000374 argc--;
375 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000376
Erik Andersene49d5ec2000-02-08 19:58:47 +0000377 if (been_there_done_that == 1 || argc < 1) {
378 const struct Applet *a = applets;
379
380 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
381 BB_VER, BB_BT);
382 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
383 fprintf(stderr, " or: [function] [arguments]...\n\n");
384 fprintf(stderr,
Erik Andersen5661fe02000-04-05 01:00:52 +0000385 "\tMost people will create a link to busybox for each function\n"
386 "\tname, and busybox will act like whatever you invoke it as.\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000387 fprintf(stderr, "\nCurrently defined functions:\n");
388
389 while (a->name != 0) {
390 col +=
391 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
392 (a++)->name);
393 if (col > 60 && a->name != 0) {
394 fprintf(stderr, ",\n");
395 col = 0;
396 }
397 }
398 fprintf(stderr, "\n\n");
399 exit(-1);
400 } else {
401 /* If we've already been here once, exit now */
402 been_there_done_that = 1;
403 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000404 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000405}
Erik Andersen029011b2000-03-04 21:19:32 +0000406
407/*
408Local Variables:
409c-file-style: "linux"
410c-basic-offset: 4
411tab-width: 4
412End:
413*/