blob: 5f1c56bc3b7ba94e87a785af4655ad9a0516950e [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
Eric Andersen86ab8a32000-06-02 03:21:42 +000035#ifdef BB_AR
36 {"ar", ar_main, _BB_DIR_USR_BIN},
37#endif
Erik Andersen298854f2000-03-23 01:09:18 +000038#ifdef BB_BASENAME
Erik Andersend75af992000-03-16 08:09:09 +000039 {"basename", basename_main, _BB_DIR_USR_BIN},
Erik Andersene2729152000-02-18 21:34:17 +000040#endif
Erik Andersend75af992000-03-16 08:09:09 +000041 {"busybox", busybox_main, _BB_DIR_BIN},
Erik Andersen298854f2000-03-23 01:09:18 +000042#ifdef BB_BLOCK_DEVICE
Erik Andersend75af992000-03-16 08:09:09 +000043 {"block_device", block_device_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000044#endif
Erik Andersen298854f2000-03-23 01:09:18 +000045#ifdef BB_CAT
Erik Andersend75af992000-03-16 08:09:09 +000046 {"cat", cat_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000047#endif
Erik Andersen298854f2000-03-23 01:09:18 +000048#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersen5e1189e2000-04-15 16:34:54 +000049 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
50#endif
51#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000052 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
53#endif
Erik Andersen298854f2000-03-23 01:09:18 +000054#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000055 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
56#endif
Erik Andersen298854f2000-03-23 01:09:18 +000057#ifdef BB_CHROOT
Erik Andersend75af992000-03-16 08:09:09 +000058 {"chroot", chroot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000059#endif
Erik Andersen298854f2000-03-23 01:09:18 +000060#ifdef BB_CLEAR
Erik Andersend75af992000-03-16 08:09:09 +000061 {"clear", clear_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000062#endif
Erik Andersen298854f2000-03-23 01:09:18 +000063#ifdef BB_CHVT
Erik Andersend75af992000-03-16 08:09:09 +000064 {"chvt", chvt_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +000065#endif
Erik Andersen298854f2000-03-23 01:09:18 +000066#ifdef BB_CP_MV
Erik Andersend75af992000-03-16 08:09:09 +000067 {"cp", cp_mv_main, _BB_DIR_BIN},
68#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000069#ifdef BB_CUT
70 {"cut", cut_main, _BB_DIR_USR_BIN},
71#endif
Erik Andersen298854f2000-03-23 01:09:18 +000072#ifdef BB_DATE
Erik Andersend75af992000-03-16 08:09:09 +000073 {"date", date_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000074#endif
John Beppu00216792000-06-21 19:06:16 +000075#ifdef BB_DC
76 {"dc", dc_main, _BB_DIR_USR_BIN},
77#endif
Erik Andersen298854f2000-03-23 01:09:18 +000078#ifdef BB_DD
Erik Andersend75af992000-03-16 08:09:09 +000079 {"dd", dd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000080#endif
Erik Andersen298854f2000-03-23 01:09:18 +000081#ifdef BB_DF
Erik Andersend75af992000-03-16 08:09:09 +000082 {"df", df_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000083#endif
Erik Andersen298854f2000-03-23 01:09:18 +000084#ifdef BB_DIRNAME
Erik Andersend75af992000-03-16 08:09:09 +000085 {"dirname", dirname_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +000086#endif
Erik Andersen298854f2000-03-23 01:09:18 +000087#ifdef BB_DMESG
Erik Andersend75af992000-03-16 08:09:09 +000088 {"dmesg", dmesg_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000089#endif
Erik Andersen298854f2000-03-23 01:09:18 +000090#ifdef BB_DU
Erik Andersend75af992000-03-16 08:09:09 +000091 {"du", du_main, _BB_DIR_BIN},
John Beppu7a986061999-12-09 18:29:29 +000092#endif
Erik Andersen298854f2000-03-23 01:09:18 +000093#ifdef BB_DUTMP
Erik Andersend75af992000-03-16 08:09:09 +000094 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
95#endif
Erik Andersen298854f2000-03-23 01:09:18 +000096#ifdef BB_ECHO
Erik Andersend75af992000-03-16 08:09:09 +000097 {"echo", echo_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000098#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +000099#ifdef BB_TRUE_FALSE
100 {"false", false_main, _BB_DIR_BIN},
101#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000102#ifdef BB_FBSET
Erik Andersend75af992000-03-16 08:09:09 +0000103 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
Erik Andersen1c5b2581999-12-16 20:59:36 +0000104#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000105#ifdef BB_FDFLUSH
Erik Andersend75af992000-03-16 08:09:09 +0000106 {"fdflush", fdflush_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000107#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000108#ifdef BB_FIND
Erik Andersend75af992000-03-16 08:09:09 +0000109 {"find", find_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000110#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000111#ifdef BB_FREE
Erik Andersend75af992000-03-16 08:09:09 +0000112 {"free", free_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000113#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000114#ifdef BB_FREERAMDISK
Erik Andersend75af992000-03-16 08:09:09 +0000115 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
Erik Andersen64371702000-03-04 22:23:27 +0000116#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000117#ifdef BB_DEALLOCVT
Erik Andersend75af992000-03-16 08:09:09 +0000118 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000119#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000120#ifdef BB_FSCK_MINIX
Erik Andersend75af992000-03-16 08:09:09 +0000121 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
Eric Andersene494fdd1999-10-19 20:23:03 +0000122#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000123#ifdef BB_GREP
Erik Andersend75af992000-03-16 08:09:09 +0000124 {"grep", grep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000125#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000126#ifdef BB_GUNZIP
127 {"gunzip", gunzip_main, _BB_DIR_BIN},
128#endif
129#ifdef BB_GZIP
130 {"gzip", gzip_main, _BB_DIR_BIN},
131#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000132#ifdef BB_HALT
Erik Andersend75af992000-03-16 08:09:09 +0000133 {"halt", halt_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000134#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000135#ifdef BB_HEAD
Erik Andersend75af992000-03-16 08:09:09 +0000136 {"head", head_main, _BB_DIR_BIN},
John Beppu3157b1f1999-12-10 07:42:50 +0000137#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000138#ifdef BB_HOSTID
Erik Andersend75af992000-03-16 08:09:09 +0000139 {"hostid", hostid_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000140#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000141#ifdef BB_HOSTNAME
Erik Andersend75af992000-03-16 08:09:09 +0000142 {"hostname", hostname_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000143#endif
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000144#ifdef BB_ID
145 {"id", id_main, _BB_DIR_USR_BIN},
146#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000147#ifdef BB_INIT
Erik Andersend75af992000-03-16 08:09:09 +0000148 {"init", init_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000149#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000150#ifdef BB_INSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000151 {"insmod", insmod_main, _BB_DIR_SBIN},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000152#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000153#ifdef BB_KILL
Erik Andersend75af992000-03-16 08:09:09 +0000154 {"kill", kill_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000155#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000156#ifdef BB_KILLALL
Erik Andersend75af992000-03-16 08:09:09 +0000157 {"killall", kill_main, _BB_DIR_USR_BIN},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000158#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000159#ifdef BB_LENGTH
Erik Andersend75af992000-03-16 08:09:09 +0000160 {"length", length_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000161#endif
Erik Andersen9a8195c2000-04-18 23:32:10 +0000162#ifdef BB_LINUXRC
Erik Andersen5e1189e2000-04-15 16:34:54 +0000163 {"linuxrc", init_main, _BB_DIR_ROOT},
164#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000165#ifdef BB_LN
Erik Andersend75af992000-03-16 08:09:09 +0000166 {"ln", ln_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000167#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000168#ifdef BB_LOADACM
Erik Andersend75af992000-03-16 08:09:09 +0000169 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000170#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000171#ifdef BB_LOADFONT
Erik Andersend75af992000-03-16 08:09:09 +0000172 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000173#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000174#ifdef BB_LOADKMAP
Erik Andersend75af992000-03-16 08:09:09 +0000175 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000176#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000177#ifdef BB_LOGGER
178 {"logger", logger_main, _BB_DIR_USR_BIN},
179#endif
180#ifdef BB_LOGNAME
181 {"logname", logname_main, _BB_DIR_USR_BIN},
182#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000183#ifdef BB_LS
Erik Andersend75af992000-03-16 08:09:09 +0000184 {"ls", ls_main, _BB_DIR_BIN},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000185#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000186#ifdef BB_LSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000187 {"lsmod", lsmod_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000188#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000189#ifdef BB_MAKEDEVS
Erik Andersend75af992000-03-16 08:09:09 +0000190 {"makedevs", makedevs_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000191#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000192#ifdef BB_MD5SUM
193 {"md5sum", md5sum_main, _BB_DIR_USR_BIN},
194#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000195#ifdef BB_MKDIR
Erik Andersend75af992000-03-16 08:09:09 +0000196 {"mkdir", mkdir_main, _BB_DIR_BIN},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000197#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000198#ifdef BB_MKFIFO
Erik Andersend75af992000-03-16 08:09:09 +0000199 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
Eric Andersen19db07b1999-12-11 08:41:28 +0000200#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000201#ifdef BB_MKFS_MINIX
202 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
203#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000204#ifdef BB_MKNOD
Erik Andersend75af992000-03-16 08:09:09 +0000205 {"mknod", mknod_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000206#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000207#ifdef BB_MKSWAP
Erik Andersend75af992000-03-16 08:09:09 +0000208 {"mkswap", mkswap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000209#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000210#ifdef BB_MKTEMP
211 {"mktemp", mktemp_main, _BB_DIR_BIN},
212#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000213#ifdef BB_NC
214 {"nc", nc_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000215#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000216#ifdef BB_MORE
Erik Andersend75af992000-03-16 08:09:09 +0000217 {"more", more_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000218#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000219#ifdef BB_MOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000220 {"mount", mount_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000221#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000222#ifdef BB_MT
Erik Andersend75af992000-03-16 08:09:09 +0000223 {"mt", mt_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000224#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000225#ifdef BB_CP_MV
226 {"mv", cp_mv_main, _BB_DIR_BIN},
227#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000228#ifdef BB_NSLOOKUP
Erik Andersend75af992000-03-16 08:09:09 +0000229 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
John Beppub332e772000-01-29 12:59:01 +0000230#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000231#ifdef BB_PING
Erik Andersend75af992000-03-16 08:09:09 +0000232 {"ping", ping_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000233#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000234#ifdef BB_POWEROFF
Erik Andersend75af992000-03-16 08:09:09 +0000235 {"poweroff", poweroff_main, _BB_DIR_SBIN},
Eric Andersen2cb55071999-12-10 08:25:07 +0000236#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000237#ifdef BB_PRINTF
Erik Andersend75af992000-03-16 08:09:09 +0000238 {"printf", printf_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000239#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000240#ifdef BB_PS
Erik Andersend75af992000-03-16 08:09:09 +0000241 {"ps", ps_main, _BB_DIR_BIN},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000242#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000243#ifdef BB_PWD
Erik Andersend75af992000-03-16 08:09:09 +0000244 {"pwd", pwd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000245#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000246#ifdef BB_REBOOT
Erik Andersend75af992000-03-16 08:09:09 +0000247 {"reboot", reboot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000248#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000249#ifdef BB_RM
Erik Andersend75af992000-03-16 08:09:09 +0000250 {"rm", rm_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000251#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000252#ifdef BB_RMDIR
Erik Andersend75af992000-03-16 08:09:09 +0000253 {"rmdir", rmdir_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000254#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000255#ifdef BB_RMMOD
Erik Andersend75af992000-03-16 08:09:09 +0000256 {"rmmod", rmmod_main, _BB_DIR_SBIN},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000257#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000258#ifdef BB_SED
Erik Andersend75af992000-03-16 08:09:09 +0000259 {"sed", sed_main, _BB_DIR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000260#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000261#ifdef BB_SETKEYCODES
262 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000263#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000264#ifdef BB_SFDISK
Erik Andersend75af992000-03-16 08:09:09 +0000265 {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
Eric Andersene77ae3a1999-10-19 20:03:34 +0000266#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000267#ifdef BB_SH
268 {"sh", shell_main, _BB_DIR_BIN},
269#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000270#ifdef BB_SLEEP
Erik Andersend75af992000-03-16 08:09:09 +0000271 {"sleep", sleep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000272#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000273#ifdef BB_SORT
Erik Andersend75af992000-03-16 08:09:09 +0000274 {"sort", sort_main, _BB_DIR_BIN},
John Beppu019513a1999-12-22 17:57:31 +0000275#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000276#ifdef BB_SYNC
Erik Andersend75af992000-03-16 08:09:09 +0000277 {"sync", sync_main, _BB_DIR_BIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000278#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000279#ifdef BB_SYSLOGD
Erik Andersend75af992000-03-16 08:09:09 +0000280 {"syslogd", syslogd_main, _BB_DIR_SBIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000281#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000282#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000283 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
284#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000285#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000286 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000287#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000288#ifdef BB_TAIL
Erik Andersend75af992000-03-16 08:09:09 +0000289 {"tail", tail_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000290#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000291#ifdef BB_TAR
Erik Andersend75af992000-03-16 08:09:09 +0000292 {"tar", tar_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000293#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000294#ifdef BB_TELNET
Erik Andersend75af992000-03-16 08:09:09 +0000295 {"telnet", telnet_main, _BB_DIR_USR_BIN},
296#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000297#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000298 {"test", test_main, _BB_DIR_USR_BIN},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000299#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000300#ifdef BB_TEE
Erik Andersend75af992000-03-16 08:09:09 +0000301 {"tee", tee_main, _BB_DIR_BIN},
John Beppu059f1521999-12-10 05:27:16 +0000302#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000303#ifdef BB_TOUCH
Erik Andersend75af992000-03-16 08:09:09 +0000304 {"touch", touch_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000305#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000306#ifdef BB_TR
Erik Andersend75af992000-03-16 08:09:09 +0000307 {"tr", tr_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +0000308#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000309#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000310 {"true", true_main, _BB_DIR_BIN},
311#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000312#ifdef BB_TTY
Erik Andersend75af992000-03-16 08:09:09 +0000313 {"tty", tty_main, _BB_DIR_USR_BIN},
Erik Andersen05df2392000-01-13 04:43:48 +0000314#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000315#ifdef BB_UMOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000316 {"umount", umount_main, _BB_DIR_BIN},
Erik Andersen66be5e72000-03-05 07:52:05 +0000317#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000318#ifdef BB_UNAME
Erik Andersend75af992000-03-16 08:09:09 +0000319 {"uname", uname_main, _BB_DIR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000320#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000321#ifdef BB_UNIQ
Erik Andersena6c75222000-04-18 00:00:52 +0000322 {"uniq", uniq_main, _BB_DIR_USR_BIN},
John Beppuabb47722000-01-06 00:48:21 +0000323#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000324#ifdef BB_UPDATE
Erik Andersend75af992000-03-16 08:09:09 +0000325 {"update", update_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000326#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000327#ifdef BB_UPTIME
328 {"uptime", uptime_main, _BB_DIR_USR_BIN},
329#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000330#ifdef BB_UUENCODE
331 {"uuencode", uuencode_main, _BB_DIR_USR_BIN},
332#endif
333#ifdef BB_UUDECODE
334 {"uudecode", uudecode_main, _BB_DIR_USR_BIN},
335#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000336#ifdef BB_USLEEP
337 {"usleep", usleep_main, _BB_DIR_BIN},
338#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000339#ifdef BB_WC
Erik Andersend75af992000-03-16 08:09:09 +0000340 {"wc", wc_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000341#endif
Erik Andersen330fd2b2000-05-19 05:35:19 +0000342#ifdef BB_WHICH
343 {"which", which_main, _BB_DIR_USR_BIN},
344#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000345#ifdef BB_WHOAMI
Erik Andersend75af992000-03-16 08:09:09 +0000346 {"whoami", whoami_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000347#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000348#ifdef BB_YES
Erik Andersend75af992000-03-16 08:09:09 +0000349 {"yes", yes_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000350#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000351#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000352 {"zcat", gunzip_main, _BB_DIR_BIN},
353#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000354#ifdef BB_TEST
355 {"[", test_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000356#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000357 {0}
Eric Andersencc8ed391999-10-05 16:24:54 +0000358};
359
Erik Andersen05df2392000-01-13 04:43:48 +0000360
John Beppu8f425db2000-06-27 04:50:02 +0000361#ifdef BB_FEATURE_INSTALLER
362/*
363 * directory table
364 * this should be consistent w/ the enum, internal.h::Location,
365 * or else...
366 */
367static char* install_dir[] = {
368 "/",
369 "/bin",
370 "/sbin",
371 "/usr/bin",
372 "/usr/sbin",
373 NULL
374};
375
376/* abstract link() */
377typedef int (*__link_f)(const char *, const char *);
378
379/* create (sym)links for each applet */
380int install_links(const char *busybox, int use_symbolic_links)
381{
382 __link_f Link = link;
383
384 char command[256];
385 int i;
386 int rc = 0;
387
388 if (use_symbolic_links) Link = symlink;
389
390 for (i = 0; applets[i].name != NULL; i++) {
391 sprintf (
392 command,
393 "%s/%s",
394 install_dir[applets[i].location],
395 applets[i].name
396 );
397#if 0
398 rc |= Link(busybox, command);
399#else
400 puts(command);
401#endif
402 if (rc) {
403 fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
404 break;
405 }
406 }
407 return rc;
408}
409
410#if 0
411int uninstall_links() ?
412#endif
413#endif /* BB_FEATURE_INSTALLER */
414
Erik Andersen05df2392000-01-13 04:43:48 +0000415
Eric Andersencc8ed391999-10-05 16:24:54 +0000416int main(int argc, char **argv)
417{
Erik Andersend75af992000-03-16 08:09:09 +0000418 char *s;
419 char *name;
Erik Andersenbcd61772000-05-13 06:33:19 +0000420 const struct BB_applet *a = applets;
Eric Andersencc8ed391999-10-05 16:24:54 +0000421
John Beppu8f425db2000-06-27 04:50:02 +0000422#ifdef BB_FEATURE_INSTALLER
John Beppu27b59242000-06-27 04:56:45 +0000423 /*
424 * This style of argument parsing doesn't scale well
425 * in the event that busybox starts wanting more --options.
426 * If someone has a cleaner approach, by all means implement it.
427 */
John Beppu8f425db2000-06-27 04:50:02 +0000428 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
429 int use_symbolic_links = 0;
430
John Beppu27b59242000-06-27 04:56:45 +0000431 /* to use symlinks, or not to use symlinks... */
John Beppu8f425db2000-06-27 04:50:02 +0000432 if (argc > 2) {
433 if ((strcmp(argv[2], "-s") == 0)) {
434 use_symbolic_links = 1;
435 }
436 }
437 /*
438 * FIXME :
439 * I need a clever unix trick that'll tell
440 * me where to find the currently running
441 * busybox binary
442 */
443 return install_links("/bin/busybox", use_symbolic_links);
444 }
445#endif /* BB_FEATURE_INSTALLER */
446
Erik Andersend75af992000-03-16 08:09:09 +0000447 for (s = name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000448 if (*s++ == '/')
449 name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000450 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000451
Erik Andersen029011b2000-03-04 21:19:32 +0000452 *argv = name;
453
Erik Andersene49d5ec2000-02-08 19:58:47 +0000454 while (a->name != 0) {
455 if (strcmp(name, a->name) == 0) {
Eric Andersenb6106152000-06-19 17:25:40 +0000456 exit(((*(a->main)) (argc, argv)));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000457 }
458 a++;
459 }
Eric Andersenb6106152000-06-19 17:25:40 +0000460 return(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000461}
462
463
464int busybox_main(int argc, char **argv)
465{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000466 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000467
Erik Andersene49d5ec2000-02-08 19:58:47 +0000468 argc--;
469 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000470
Erik Andersene49d5ec2000-02-08 19:58:47 +0000471 if (been_there_done_that == 1 || argc < 1) {
Erik Andersenbcd61772000-05-13 06:33:19 +0000472 const struct BB_applet *a = applets;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000473
Erik Andersen330fd2b2000-05-19 05:35:19 +0000474 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
475 "Usage: busybox [function] [arguments]...\n"
476 " or: [function] [arguments]...\n\n"
John Beppub4f86062000-04-13 03:36:01 +0000477 "\tBusyBox is a multi-call binary that combines many common Unix\n"
478 "\tutilities into a single executable. Most people will create a\n"
479 "\tlink to busybox for each function they wish to use, and BusyBox\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000480 "\twill act like whatever it was invoked as.\n"
481 "\nCurrently defined functions:\n", BB_VER, BB_BT);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000482
483 while (a->name != 0) {
484 col +=
485 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
486 (a++)->name);
487 if (col > 60 && a->name != 0) {
488 fprintf(stderr, ",\n");
489 col = 0;
490 }
491 }
492 fprintf(stderr, "\n\n");
493 exit(-1);
Eric Andersencc8ed391999-10-05 16:24:54 +0000494 }
Eric Andersenb6106152000-06-19 17:25:40 +0000495 /* If we've already been here once, exit now */
496 been_there_done_that = 1;
497 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000498}
Erik Andersen029011b2000-03-04 21:19:32 +0000499
500/*
501Local Variables:
502c-file-style: "linux"
503c-basic-offset: 4
504tab-width: 4
505End:
506*/