blob: 44fa16994fb613459f917f84def7c9c77b307ebe [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_CAT
Erik Andersend75af992000-03-16 08:09:09 +000043 {"cat", cat_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000044#endif
Erik Andersen298854f2000-03-23 01:09:18 +000045#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersen5e1189e2000-04-15 16:34:54 +000046 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
47#endif
48#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000049 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
50#endif
Erik Andersen298854f2000-03-23 01:09:18 +000051#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000052 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
53#endif
Erik Andersen298854f2000-03-23 01:09:18 +000054#ifdef BB_CHROOT
Erik Andersend75af992000-03-16 08:09:09 +000055 {"chroot", chroot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000056#endif
Erik Andersen298854f2000-03-23 01:09:18 +000057#ifdef BB_CLEAR
Erik Andersend75af992000-03-16 08:09:09 +000058 {"clear", clear_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000059#endif
Erik Andersen298854f2000-03-23 01:09:18 +000060#ifdef BB_CHVT
Erik Andersend75af992000-03-16 08:09:09 +000061 {"chvt", chvt_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +000062#endif
Erik Andersen298854f2000-03-23 01:09:18 +000063#ifdef BB_CP_MV
Erik Andersend75af992000-03-16 08:09:09 +000064 {"cp", cp_mv_main, _BB_DIR_BIN},
65#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000066#ifdef BB_CUT
67 {"cut", cut_main, _BB_DIR_USR_BIN},
68#endif
Erik Andersen298854f2000-03-23 01:09:18 +000069#ifdef BB_DATE
Erik Andersend75af992000-03-16 08:09:09 +000070 {"date", date_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000071#endif
John Beppu00216792000-06-21 19:06:16 +000072#ifdef BB_DC
73 {"dc", dc_main, _BB_DIR_USR_BIN},
74#endif
Erik Andersen298854f2000-03-23 01:09:18 +000075#ifdef BB_DD
Erik Andersend75af992000-03-16 08:09:09 +000076 {"dd", dd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000077#endif
Erik Andersen298854f2000-03-23 01:09:18 +000078#ifdef BB_DF
Erik Andersend75af992000-03-16 08:09:09 +000079 {"df", df_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000080#endif
Erik Andersen298854f2000-03-23 01:09:18 +000081#ifdef BB_DIRNAME
Erik Andersend75af992000-03-16 08:09:09 +000082 {"dirname", dirname_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +000083#endif
Erik Andersen298854f2000-03-23 01:09:18 +000084#ifdef BB_DMESG
Erik Andersend75af992000-03-16 08:09:09 +000085 {"dmesg", dmesg_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000086#endif
Erik Andersen298854f2000-03-23 01:09:18 +000087#ifdef BB_DU
Erik Andersend75af992000-03-16 08:09:09 +000088 {"du", du_main, _BB_DIR_BIN},
John Beppu7a986061999-12-09 18:29:29 +000089#endif
Erik Andersen298854f2000-03-23 01:09:18 +000090#ifdef BB_DUTMP
Erik Andersend75af992000-03-16 08:09:09 +000091 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
92#endif
Erik Andersen298854f2000-03-23 01:09:18 +000093#ifdef BB_ECHO
Erik Andersend75af992000-03-16 08:09:09 +000094 {"echo", echo_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000095#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +000096#ifdef BB_TRUE_FALSE
97 {"false", false_main, _BB_DIR_BIN},
98#endif
Erik Andersen298854f2000-03-23 01:09:18 +000099#ifdef BB_FBSET
Erik Andersend75af992000-03-16 08:09:09 +0000100 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
Erik Andersen1c5b2581999-12-16 20:59:36 +0000101#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000102#ifdef BB_FDFLUSH
Erik Andersend75af992000-03-16 08:09:09 +0000103 {"fdflush", fdflush_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000104#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000105#ifdef BB_FIND
Erik Andersend75af992000-03-16 08:09:09 +0000106 {"find", find_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000107#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000108#ifdef BB_FREE
Erik Andersend75af992000-03-16 08:09:09 +0000109 {"free", free_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000110#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000111#ifdef BB_FREERAMDISK
Erik Andersend75af992000-03-16 08:09:09 +0000112 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
Erik Andersen64371702000-03-04 22:23:27 +0000113#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000114#ifdef BB_DEALLOCVT
Erik Andersend75af992000-03-16 08:09:09 +0000115 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000116#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000117#ifdef BB_FSCK_MINIX
Erik Andersend75af992000-03-16 08:09:09 +0000118 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
Eric Andersene494fdd1999-10-19 20:23:03 +0000119#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000120#ifdef BB_GREP
Erik Andersend75af992000-03-16 08:09:09 +0000121 {"grep", grep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000122#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000123#ifdef BB_GUNZIP
124 {"gunzip", gunzip_main, _BB_DIR_BIN},
125#endif
126#ifdef BB_GZIP
127 {"gzip", gzip_main, _BB_DIR_BIN},
128#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000129#ifdef BB_HALT
Erik Andersend75af992000-03-16 08:09:09 +0000130 {"halt", halt_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000131#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000132#ifdef BB_HEAD
Erik Andersend75af992000-03-16 08:09:09 +0000133 {"head", head_main, _BB_DIR_BIN},
John Beppu3157b1f1999-12-10 07:42:50 +0000134#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000135#ifdef BB_HOSTID
Erik Andersend75af992000-03-16 08:09:09 +0000136 {"hostid", hostid_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000137#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000138#ifdef BB_HOSTNAME
Erik Andersend75af992000-03-16 08:09:09 +0000139 {"hostname", hostname_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000140#endif
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000141#ifdef BB_ID
142 {"id", id_main, _BB_DIR_USR_BIN},
143#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000144#ifdef BB_INIT
Erik Andersend75af992000-03-16 08:09:09 +0000145 {"init", init_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000146#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000147#ifdef BB_INSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000148 {"insmod", insmod_main, _BB_DIR_SBIN},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000149#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000150#ifdef BB_KILL
Erik Andersend75af992000-03-16 08:09:09 +0000151 {"kill", kill_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000152#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000153#ifdef BB_KILLALL
Erik Andersend75af992000-03-16 08:09:09 +0000154 {"killall", kill_main, _BB_DIR_USR_BIN},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000155#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000156#ifdef BB_LENGTH
Erik Andersend75af992000-03-16 08:09:09 +0000157 {"length", length_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000158#endif
Erik Andersen9a8195c2000-04-18 23:32:10 +0000159#ifdef BB_LINUXRC
Erik Andersen5e1189e2000-04-15 16:34:54 +0000160 {"linuxrc", init_main, _BB_DIR_ROOT},
161#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000162#ifdef BB_LN
Erik Andersend75af992000-03-16 08:09:09 +0000163 {"ln", ln_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000164#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000165#ifdef BB_LOADACM
Erik Andersend75af992000-03-16 08:09:09 +0000166 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000167#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000168#ifdef BB_LOADFONT
Erik Andersend75af992000-03-16 08:09:09 +0000169 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000170#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000171#ifdef BB_LOADKMAP
Erik Andersend75af992000-03-16 08:09:09 +0000172 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000173#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000174#ifdef BB_LOGGER
175 {"logger", logger_main, _BB_DIR_USR_BIN},
176#endif
177#ifdef BB_LOGNAME
178 {"logname", logname_main, _BB_DIR_USR_BIN},
179#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000180#ifdef BB_LS
Erik Andersend75af992000-03-16 08:09:09 +0000181 {"ls", ls_main, _BB_DIR_BIN},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000182#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000183#ifdef BB_LSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000184 {"lsmod", lsmod_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000185#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000186#ifdef BB_MAKEDEVS
Erik Andersend75af992000-03-16 08:09:09 +0000187 {"makedevs", makedevs_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000188#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000189#ifdef BB_MD5SUM
190 {"md5sum", md5sum_main, _BB_DIR_USR_BIN},
191#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000192#ifdef BB_MKDIR
Erik Andersend75af992000-03-16 08:09:09 +0000193 {"mkdir", mkdir_main, _BB_DIR_BIN},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000194#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000195#ifdef BB_MKFIFO
Erik Andersend75af992000-03-16 08:09:09 +0000196 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
Eric Andersen19db07b1999-12-11 08:41:28 +0000197#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000198#ifdef BB_MKFS_MINIX
199 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
200#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000201#ifdef BB_MKNOD
Erik Andersend75af992000-03-16 08:09:09 +0000202 {"mknod", mknod_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000203#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000204#ifdef BB_MKSWAP
Erik Andersend75af992000-03-16 08:09:09 +0000205 {"mkswap", mkswap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000206#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000207#ifdef BB_MKTEMP
208 {"mktemp", mktemp_main, _BB_DIR_BIN},
209#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000210#ifdef BB_NC
211 {"nc", nc_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000212#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000213#ifdef BB_MORE
Erik Andersend75af992000-03-16 08:09:09 +0000214 {"more", more_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000215#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000216#ifdef BB_MOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000217 {"mount", mount_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000218#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000219#ifdef BB_MT
Erik Andersend75af992000-03-16 08:09:09 +0000220 {"mt", mt_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000221#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000222#ifdef BB_CP_MV
223 {"mv", cp_mv_main, _BB_DIR_BIN},
224#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000225#ifdef BB_NSLOOKUP
Erik Andersend75af992000-03-16 08:09:09 +0000226 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
John Beppub332e772000-01-29 12:59:01 +0000227#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000228#ifdef BB_PING
Erik Andersend75af992000-03-16 08:09:09 +0000229 {"ping", ping_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000230#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000231#ifdef BB_POWEROFF
Erik Andersend75af992000-03-16 08:09:09 +0000232 {"poweroff", poweroff_main, _BB_DIR_SBIN},
Eric Andersen2cb55071999-12-10 08:25:07 +0000233#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000234#ifdef BB_PRINTF
Erik Andersend75af992000-03-16 08:09:09 +0000235 {"printf", printf_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000236#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000237#ifdef BB_PS
Erik Andersend75af992000-03-16 08:09:09 +0000238 {"ps", ps_main, _BB_DIR_BIN},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000239#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000240#ifdef BB_PWD
Erik Andersend75af992000-03-16 08:09:09 +0000241 {"pwd", pwd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000242#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000243#ifdef BB_REBOOT
Erik Andersend75af992000-03-16 08:09:09 +0000244 {"reboot", reboot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000245#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000246#ifdef BB_RM
Erik Andersend75af992000-03-16 08:09:09 +0000247 {"rm", rm_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000248#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000249#ifdef BB_RMDIR
Erik Andersend75af992000-03-16 08:09:09 +0000250 {"rmdir", rmdir_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000251#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000252#ifdef BB_RMMOD
Erik Andersend75af992000-03-16 08:09:09 +0000253 {"rmmod", rmmod_main, _BB_DIR_SBIN},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000254#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000255#ifdef BB_SED
Erik Andersend75af992000-03-16 08:09:09 +0000256 {"sed", sed_main, _BB_DIR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000257#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000258#ifdef BB_SETKEYCODES
259 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000260#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000261#ifdef BB_SH
262 {"sh", shell_main, _BB_DIR_BIN},
263#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000264#ifdef BB_SLEEP
Erik Andersend75af992000-03-16 08:09:09 +0000265 {"sleep", sleep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000266#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000267#ifdef BB_SORT
Erik Andersend75af992000-03-16 08:09:09 +0000268 {"sort", sort_main, _BB_DIR_BIN},
John Beppu019513a1999-12-22 17:57:31 +0000269#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000270#ifdef BB_SYNC
Erik Andersend75af992000-03-16 08:09:09 +0000271 {"sync", sync_main, _BB_DIR_BIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000272#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000273#ifdef BB_SYSLOGD
Erik Andersend75af992000-03-16 08:09:09 +0000274 {"syslogd", syslogd_main, _BB_DIR_SBIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000275#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000276#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000277 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
278#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000279#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000280 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000281#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000282#ifdef BB_TAIL
Erik Andersend75af992000-03-16 08:09:09 +0000283 {"tail", tail_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000284#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000285#ifdef BB_TAR
Erik Andersend75af992000-03-16 08:09:09 +0000286 {"tar", tar_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000287#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000288#ifdef BB_TELNET
Erik Andersend75af992000-03-16 08:09:09 +0000289 {"telnet", telnet_main, _BB_DIR_USR_BIN},
290#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000291#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000292 {"test", test_main, _BB_DIR_USR_BIN},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000293#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000294#ifdef BB_TEE
Erik Andersend75af992000-03-16 08:09:09 +0000295 {"tee", tee_main, _BB_DIR_BIN},
John Beppu059f1521999-12-10 05:27:16 +0000296#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000297#ifdef BB_TOUCH
Erik Andersend75af992000-03-16 08:09:09 +0000298 {"touch", touch_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000299#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000300#ifdef BB_TR
Erik Andersend75af992000-03-16 08:09:09 +0000301 {"tr", tr_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +0000302#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000303#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000304 {"true", true_main, _BB_DIR_BIN},
305#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000306#ifdef BB_TTY
Erik Andersend75af992000-03-16 08:09:09 +0000307 {"tty", tty_main, _BB_DIR_USR_BIN},
Erik Andersen05df2392000-01-13 04:43:48 +0000308#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000309#ifdef BB_UMOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000310 {"umount", umount_main, _BB_DIR_BIN},
Erik Andersen66be5e72000-03-05 07:52:05 +0000311#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000312#ifdef BB_UNAME
Erik Andersend75af992000-03-16 08:09:09 +0000313 {"uname", uname_main, _BB_DIR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000314#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000315#ifdef BB_UNIQ
Erik Andersena6c75222000-04-18 00:00:52 +0000316 {"uniq", uniq_main, _BB_DIR_USR_BIN},
John Beppuabb47722000-01-06 00:48:21 +0000317#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000318#ifdef BB_UPDATE
Erik Andersend75af992000-03-16 08:09:09 +0000319 {"update", update_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000320#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000321#ifdef BB_UPTIME
322 {"uptime", uptime_main, _BB_DIR_USR_BIN},
323#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000324#ifdef BB_UUENCODE
325 {"uuencode", uuencode_main, _BB_DIR_USR_BIN},
326#endif
327#ifdef BB_UUDECODE
328 {"uudecode", uudecode_main, _BB_DIR_USR_BIN},
329#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000330#ifdef BB_USLEEP
331 {"usleep", usleep_main, _BB_DIR_BIN},
332#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000333#ifdef BB_WC
Erik Andersend75af992000-03-16 08:09:09 +0000334 {"wc", wc_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000335#endif
Erik Andersen330fd2b2000-05-19 05:35:19 +0000336#ifdef BB_WHICH
337 {"which", which_main, _BB_DIR_USR_BIN},
338#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000339#ifdef BB_WHOAMI
Erik Andersend75af992000-03-16 08:09:09 +0000340 {"whoami", whoami_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000341#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000342#ifdef BB_YES
Erik Andersend75af992000-03-16 08:09:09 +0000343 {"yes", yes_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000344#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000345#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000346 {"zcat", gunzip_main, _BB_DIR_BIN},
347#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000348#ifdef BB_TEST
349 {"[", test_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000350#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000351 {0}
Eric Andersencc8ed391999-10-05 16:24:54 +0000352};
353
Erik Andersen05df2392000-01-13 04:43:48 +0000354
John Beppu8f425db2000-06-27 04:50:02 +0000355#ifdef BB_FEATURE_INSTALLER
356/*
357 * directory table
John Beppueb028332000-06-28 00:55:31 +0000358 * this should be consistent w/ the enum, internal.h::Location,
359 * or else...
John Beppu8f425db2000-06-27 04:50:02 +0000360 */
361static char* install_dir[] = {
John Beppueb028332000-06-28 00:55:31 +0000362 "/",
363 "/bin",
364 "/sbin",
365 "/usr/bin",
366 "/usr/sbin",
John Beppu8f425db2000-06-27 04:50:02 +0000367};
368
369/* abstract link() */
370typedef int (*__link_f)(const char *, const char *);
371
John Beppu7cdc76d2000-06-28 00:41:26 +0000372/*
373 * Where in the filesystem is this busybox?
374 * [return]
375 * malloc'd string w/ full pathname of busybox's location
376 * NULL on failure
377 */
378static char *busybox_fullpath()
379{
John Beppueb028332000-06-28 00:55:31 +0000380 pid_t pid;
381 char path[256];
382 char proc[256];
383 int len;
John Beppu7cdc76d2000-06-28 00:41:26 +0000384
385 pid = getpid();
386 sprintf(proc, "/proc/%d/exe", pid);
387 len = readlink(proc, path, 256);
388 if (len != -1) {
389 path[len] = 0;
390 } else {
391 fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
392 return NULL;
393 }
394 return strdup(path);
395}
396
John Beppu8f425db2000-06-27 04:50:02 +0000397/* create (sym)links for each applet */
John Beppu495869f2000-06-27 07:54:33 +0000398static int install_links(const char *busybox, int use_symbolic_links)
John Beppu8f425db2000-06-27 04:50:02 +0000399{
John Beppueb028332000-06-28 00:55:31 +0000400 __link_f Link = link;
John Beppu8f425db2000-06-27 04:50:02 +0000401
John Beppueb028332000-06-28 00:55:31 +0000402 char command[256];
403 int i;
404 int rc = 0;
John Beppu8f425db2000-06-27 04:50:02 +0000405
406 if (use_symbolic_links) Link = symlink;
407
John Beppueb028332000-06-28 00:55:31 +0000408 for (i = 0; applets[i].name != NULL; i++) {
409 sprintf (
John Beppu8f425db2000-06-27 04:50:02 +0000410 command,
411 "%s/%s",
412 install_dir[applets[i].location],
413 applets[i].name
414 );
John Beppu7cdc76d2000-06-28 00:41:26 +0000415#if 1
John Beppueb028332000-06-28 00:55:31 +0000416 rc |= Link(busybox, command);
John Beppu8f425db2000-06-27 04:50:02 +0000417#else
John Beppueb028332000-06-28 00:55:31 +0000418 puts(command);
John Beppu8f425db2000-06-27 04:50:02 +0000419#endif
420 if (rc) {
421 fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
John Beppu8f425db2000-06-27 04:50:02 +0000422 }
John Beppueb028332000-06-28 00:55:31 +0000423 }
John Beppu8f425db2000-06-27 04:50:02 +0000424 return rc;
425}
426
427#if 0
428int uninstall_links() ?
429#endif
430#endif /* BB_FEATURE_INSTALLER */
431
Erik Andersen05df2392000-01-13 04:43:48 +0000432
Eric Andersencc8ed391999-10-05 16:24:54 +0000433int main(int argc, char **argv)
434{
Erik Andersend75af992000-03-16 08:09:09 +0000435 char *s;
436 char *name;
Erik Andersenbcd61772000-05-13 06:33:19 +0000437 const struct BB_applet *a = applets;
Eric Andersencc8ed391999-10-05 16:24:54 +0000438
John Beppu8f425db2000-06-27 04:50:02 +0000439#ifdef BB_FEATURE_INSTALLER
John Beppu27b59242000-06-27 04:56:45 +0000440 /*
441 * This style of argument parsing doesn't scale well
442 * in the event that busybox starts wanting more --options.
443 * If someone has a cleaner approach, by all means implement it.
444 */
John Beppu8f425db2000-06-27 04:50:02 +0000445 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
446 int use_symbolic_links = 0;
John Beppu7cdc76d2000-06-28 00:41:26 +0000447 int rc = 0;
448 char *busybox;
John Beppu8f425db2000-06-27 04:50:02 +0000449
John Beppu27b59242000-06-27 04:56:45 +0000450 /* to use symlinks, or not to use symlinks... */
John Beppu8f425db2000-06-27 04:50:02 +0000451 if (argc > 2) {
452 if ((strcmp(argv[2], "-s") == 0)) {
453 use_symbolic_links = 1;
454 }
455 }
John Beppu7cdc76d2000-06-28 00:41:26 +0000456
457 /* link */
458 busybox = busybox_fullpath();
459 if (busybox) {
460 install_links(busybox, use_symbolic_links);
461 free(busybox);
462 } else {
463 rc = 1;
464 }
465 return rc;
John Beppu8f425db2000-06-27 04:50:02 +0000466 }
467#endif /* BB_FEATURE_INSTALLER */
468
Erik Andersend75af992000-03-16 08:09:09 +0000469 for (s = name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000470 if (*s++ == '/')
471 name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000472 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000473
Erik Andersen029011b2000-03-04 21:19:32 +0000474 *argv = name;
475
Eric Andersen5d41d602000-06-29 20:20:14 +0000476#ifdef BB_SH
477 /* Add in a special case hack -- whenever **argv == '-'
478 * (i.e. '-su' or '-sh') always invoke the shell */
479 if (**argv == '-')
480 exit(((*(shell_main)) (argc, argv)));
481#endif
482
Erik Andersene49d5ec2000-02-08 19:58:47 +0000483 while (a->name != 0) {
484 if (strcmp(name, a->name) == 0) {
Eric Andersenb6106152000-06-19 17:25:40 +0000485 exit(((*(a->main)) (argc, argv)));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000486 }
487 a++;
488 }
Eric Andersenb6106152000-06-19 17:25:40 +0000489 return(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000490}
491
492
493int busybox_main(int argc, char **argv)
494{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000495 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000496
Erik Andersene49d5ec2000-02-08 19:58:47 +0000497 argc--;
498 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000499
Erik Andersene49d5ec2000-02-08 19:58:47 +0000500 if (been_there_done_that == 1 || argc < 1) {
Erik Andersenbcd61772000-05-13 06:33:19 +0000501 const struct BB_applet *a = applets;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000502
Erik Andersen330fd2b2000-05-19 05:35:19 +0000503 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
504 "Usage: busybox [function] [arguments]...\n"
505 " or: [function] [arguments]...\n\n"
John Beppub4f86062000-04-13 03:36:01 +0000506 "\tBusyBox is a multi-call binary that combines many common Unix\n"
507 "\tutilities into a single executable. Most people will create a\n"
508 "\tlink to busybox for each function they wish to use, and BusyBox\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000509 "\twill act like whatever it was invoked as.\n"
510 "\nCurrently defined functions:\n", BB_VER, BB_BT);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000511
512 while (a->name != 0) {
513 col +=
514 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
515 (a++)->name);
516 if (col > 60 && a->name != 0) {
517 fprintf(stderr, ",\n");
518 col = 0;
519 }
520 }
521 fprintf(stderr, "\n\n");
522 exit(-1);
Eric Andersencc8ed391999-10-05 16:24:54 +0000523 }
Eric Andersenb6106152000-06-19 17:25:40 +0000524 /* If we've already been here once, exit now */
525 been_there_done_that = 1;
526 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000527}
Erik Andersen029011b2000-03-04 21:19:32 +0000528
529/*
530Local Variables:
531c-file-style: "linux"
532c-basic-offset: 4
533tab-width: 4
534End:
535*/