blob: a88761aa2d33a767a2b3aa44a67883828d00305f [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
Pavel Roskin9c5fcc32000-07-17 23:45:12 +00007#define bb_need_full_version
8#define BB_DECLARE_EXTERN
9#include "messages.c"
10
Eric Andersencc8ed391999-10-05 16:24:54 +000011static int been_there_done_that = 0;
12
Erik Andersen31638212000-01-15 22:28:50 +000013/* It has been alledged that doing such things can
14 * help reduce binary size when staticly linking,
15 * of course with glibc, this is unlikely as long
16 * as we use things like printf -- perhaps a printf
17 * replacement may be in order
18 */
Erik Andersen05df2392000-01-13 04:43:48 +000019#if 0
Erik Andersene49d5ec2000-02-08 19:58:47 +000020void exit(int status) __attribute__ ((noreturn));
21void exit(int status)
22{
23 _exit(status);
24};
25void abort(void) __attribute__ ((__noreturn__));
26void abort(void)
27{
28 _exit(0);
29};
30int atexit(void (*__func) (void))
31{
32 _exit(0);
33};
Erik Andersen05df2392000-01-13 04:43:48 +000034void *__libc_stack_end;
35#endif
36
Erik Andersenbcd61772000-05-13 06:33:19 +000037const struct BB_applet applets[] = {
Eric Andersencc8ed391999-10-05 16:24:54 +000038
Eric Andersen86ab8a32000-06-02 03:21:42 +000039#ifdef BB_AR
40 {"ar", ar_main, _BB_DIR_USR_BIN},
41#endif
Erik Andersen298854f2000-03-23 01:09:18 +000042#ifdef BB_BASENAME
Erik Andersend75af992000-03-16 08:09:09 +000043 {"basename", basename_main, _BB_DIR_USR_BIN},
Erik Andersene2729152000-02-18 21:34:17 +000044#endif
Erik Andersend75af992000-03-16 08:09:09 +000045 {"busybox", busybox_main, _BB_DIR_BIN},
Erik Andersen298854f2000-03-23 01:09:18 +000046#ifdef BB_CAT
Erik Andersend75af992000-03-16 08:09:09 +000047 {"cat", cat_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000048#endif
Erik Andersen298854f2000-03-23 01:09:18 +000049#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersen5e1189e2000-04-15 16:34:54 +000050 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
51#endif
52#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000053 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
54#endif
Erik Andersen298854f2000-03-23 01:09:18 +000055#ifdef BB_CHMOD_CHOWN_CHGRP
Erik Andersend75af992000-03-16 08:09:09 +000056 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
57#endif
Erik Andersen298854f2000-03-23 01:09:18 +000058#ifdef BB_CHROOT
Erik Andersend75af992000-03-16 08:09:09 +000059 {"chroot", chroot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000060#endif
Erik Andersen298854f2000-03-23 01:09:18 +000061#ifdef BB_CLEAR
Erik Andersend75af992000-03-16 08:09:09 +000062 {"clear", clear_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000063#endif
Erik Andersen298854f2000-03-23 01:09:18 +000064#ifdef BB_CHVT
Erik Andersend75af992000-03-16 08:09:09 +000065 {"chvt", chvt_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +000066#endif
Erik Andersen298854f2000-03-23 01:09:18 +000067#ifdef BB_CP_MV
Erik Andersend75af992000-03-16 08:09:09 +000068 {"cp", cp_mv_main, _BB_DIR_BIN},
69#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000070#ifdef BB_CUT
71 {"cut", cut_main, _BB_DIR_USR_BIN},
72#endif
Erik Andersen298854f2000-03-23 01:09:18 +000073#ifdef BB_DATE
Erik Andersend75af992000-03-16 08:09:09 +000074 {"date", date_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000075#endif
John Beppu00216792000-06-21 19:06:16 +000076#ifdef BB_DC
77 {"dc", dc_main, _BB_DIR_USR_BIN},
78#endif
Erik Andersen298854f2000-03-23 01:09:18 +000079#ifdef BB_DD
Erik Andersend75af992000-03-16 08:09:09 +000080 {"dd", dd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000081#endif
Erik Andersen298854f2000-03-23 01:09:18 +000082#ifdef BB_DF
Erik Andersend75af992000-03-16 08:09:09 +000083 {"df", df_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000084#endif
Erik Andersen298854f2000-03-23 01:09:18 +000085#ifdef BB_DIRNAME
Erik Andersend75af992000-03-16 08:09:09 +000086 {"dirname", dirname_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +000087#endif
Erik Andersen298854f2000-03-23 01:09:18 +000088#ifdef BB_DMESG
Erik Andersend75af992000-03-16 08:09:09 +000089 {"dmesg", dmesg_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +000090#endif
Erik Andersen298854f2000-03-23 01:09:18 +000091#ifdef BB_DU
Erik Andersend75af992000-03-16 08:09:09 +000092 {"du", du_main, _BB_DIR_BIN},
John Beppu7a986061999-12-09 18:29:29 +000093#endif
Eric Andersen61dc0572000-07-11 17:29:36 +000094#ifdef BB_DUMPKMAP
95 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
96#endif
Erik Andersen298854f2000-03-23 01:09:18 +000097#ifdef BB_DUTMP
Erik Andersend75af992000-03-16 08:09:09 +000098 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
99#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000100#ifdef BB_ECHO
Erik Andersend75af992000-03-16 08:09:09 +0000101 {"echo", echo_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000102#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000103#ifdef BB_TRUE_FALSE
104 {"false", false_main, _BB_DIR_BIN},
105#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000106#ifdef BB_FBSET
Erik Andersend75af992000-03-16 08:09:09 +0000107 {"fbset", fbset_main, _BB_DIR_USR_SBIN},
Erik Andersen1c5b2581999-12-16 20:59:36 +0000108#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000109#ifdef BB_FDFLUSH
Erik Andersend75af992000-03-16 08:09:09 +0000110 {"fdflush", fdflush_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000111#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000112#ifdef BB_FIND
Erik Andersend75af992000-03-16 08:09:09 +0000113 {"find", find_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000114#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000115#ifdef BB_FREE
Erik Andersend75af992000-03-16 08:09:09 +0000116 {"free", free_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000117#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000118#ifdef BB_FREERAMDISK
Erik Andersend75af992000-03-16 08:09:09 +0000119 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
Erik Andersen64371702000-03-04 22:23:27 +0000120#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000121#ifdef BB_DEALLOCVT
Erik Andersend75af992000-03-16 08:09:09 +0000122 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000123#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000124#ifdef BB_FSCK_MINIX
Erik Andersend75af992000-03-16 08:09:09 +0000125 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
Eric Andersene494fdd1999-10-19 20:23:03 +0000126#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000127#ifdef BB_GREP
Erik Andersend75af992000-03-16 08:09:09 +0000128 {"grep", grep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000129#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000130#ifdef BB_GUNZIP
131 {"gunzip", gunzip_main, _BB_DIR_BIN},
132#endif
133#ifdef BB_GZIP
134 {"gzip", gzip_main, _BB_DIR_BIN},
135#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000136#ifdef BB_HALT
Erik Andersend75af992000-03-16 08:09:09 +0000137 {"halt", halt_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000138#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000139#ifdef BB_HEAD
Erik Andersend75af992000-03-16 08:09:09 +0000140 {"head", head_main, _BB_DIR_BIN},
John Beppu3157b1f1999-12-10 07:42:50 +0000141#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000142#ifdef BB_HOSTID
Erik Andersend75af992000-03-16 08:09:09 +0000143 {"hostid", hostid_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000144#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000145#ifdef BB_HOSTNAME
Erik Andersend75af992000-03-16 08:09:09 +0000146 {"hostname", hostname_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000147#endif
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000148#ifdef BB_ID
149 {"id", id_main, _BB_DIR_USR_BIN},
150#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000151#ifdef BB_INIT
Erik Andersend75af992000-03-16 08:09:09 +0000152 {"init", init_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000153#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000154#ifdef BB_INSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000155 {"insmod", insmod_main, _BB_DIR_SBIN},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000156#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000157#ifdef BB_KILL
Erik Andersend75af992000-03-16 08:09:09 +0000158 {"kill", kill_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000159#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000160#ifdef BB_KILLALL
Erik Andersend75af992000-03-16 08:09:09 +0000161 {"killall", kill_main, _BB_DIR_USR_BIN},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000162#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000163#ifdef BB_LENGTH
Erik Andersend75af992000-03-16 08:09:09 +0000164 {"length", length_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000165#endif
Erik Andersen9a8195c2000-04-18 23:32:10 +0000166#ifdef BB_LINUXRC
Erik Andersen5e1189e2000-04-15 16:34:54 +0000167 {"linuxrc", init_main, _BB_DIR_ROOT},
168#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000169#ifdef BB_LN
Erik Andersend75af992000-03-16 08:09:09 +0000170 {"ln", ln_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000171#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000172#ifdef BB_LOADACM
Erik Andersend75af992000-03-16 08:09:09 +0000173 {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000174#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000175#ifdef BB_LOADFONT
Erik Andersend75af992000-03-16 08:09:09 +0000176 {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000177#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000178#ifdef BB_LOADKMAP
Erik Andersend75af992000-03-16 08:09:09 +0000179 {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000180#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000181#ifdef BB_LOGGER
182 {"logger", logger_main, _BB_DIR_USR_BIN},
183#endif
184#ifdef BB_LOGNAME
185 {"logname", logname_main, _BB_DIR_USR_BIN},
186#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000187#ifdef BB_LS
Erik Andersend75af992000-03-16 08:09:09 +0000188 {"ls", ls_main, _BB_DIR_BIN},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000189#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000190#ifdef BB_LSMOD
Erik Andersend75af992000-03-16 08:09:09 +0000191 {"lsmod", lsmod_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000192#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000193#ifdef BB_MAKEDEVS
Erik Andersend75af992000-03-16 08:09:09 +0000194 {"makedevs", makedevs_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000195#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000196#ifdef BB_MD5SUM
197 {"md5sum", md5sum_main, _BB_DIR_USR_BIN},
198#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000199#ifdef BB_MKDIR
Erik Andersend75af992000-03-16 08:09:09 +0000200 {"mkdir", mkdir_main, _BB_DIR_BIN},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000201#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000202#ifdef BB_MKFIFO
Erik Andersend75af992000-03-16 08:09:09 +0000203 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
Eric Andersen19db07b1999-12-11 08:41:28 +0000204#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000205#ifdef BB_MKFS_MINIX
206 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
207#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000208#ifdef BB_MKNOD
Erik Andersend75af992000-03-16 08:09:09 +0000209 {"mknod", mknod_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000210#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000211#ifdef BB_MKSWAP
Erik Andersend75af992000-03-16 08:09:09 +0000212 {"mkswap", mkswap_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000213#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000214#ifdef BB_MKTEMP
215 {"mktemp", mktemp_main, _BB_DIR_BIN},
216#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000217#ifdef BB_NC
218 {"nc", nc_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000219#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000220#ifdef BB_MORE
Erik Andersend75af992000-03-16 08:09:09 +0000221 {"more", more_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000222#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000223#ifdef BB_MOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000224 {"mount", mount_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000225#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000226#ifdef BB_MT
Erik Andersend75af992000-03-16 08:09:09 +0000227 {"mt", mt_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000228#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000229#ifdef BB_CP_MV
230 {"mv", cp_mv_main, _BB_DIR_BIN},
231#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000232#ifdef BB_NSLOOKUP
Erik Andersend75af992000-03-16 08:09:09 +0000233 {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
John Beppub332e772000-01-29 12:59:01 +0000234#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000235#ifdef BB_PING
Erik Andersend75af992000-03-16 08:09:09 +0000236 {"ping", ping_main, _BB_DIR_BIN},
Eric Andersen485b9551999-12-07 23:14:59 +0000237#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000238#ifdef BB_POWEROFF
Erik Andersend75af992000-03-16 08:09:09 +0000239 {"poweroff", poweroff_main, _BB_DIR_SBIN},
Eric Andersen2cb55071999-12-10 08:25:07 +0000240#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000241#ifdef BB_PRINTF
Erik Andersend75af992000-03-16 08:09:09 +0000242 {"printf", printf_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000243#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000244#ifdef BB_PS
Erik Andersend75af992000-03-16 08:09:09 +0000245 {"ps", ps_main, _BB_DIR_BIN},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000246#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000247#ifdef BB_PWD
Erik Andersend75af992000-03-16 08:09:09 +0000248 {"pwd", pwd_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000249#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000250#ifdef BB_REBOOT
Erik Andersend75af992000-03-16 08:09:09 +0000251 {"reboot", reboot_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000252#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000253#ifdef BB_RM
Erik Andersend75af992000-03-16 08:09:09 +0000254 {"rm", rm_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000255#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000256#ifdef BB_RMDIR
Erik Andersend75af992000-03-16 08:09:09 +0000257 {"rmdir", rmdir_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000258#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000259#ifdef BB_RMMOD
Erik Andersend75af992000-03-16 08:09:09 +0000260 {"rmmod", rmmod_main, _BB_DIR_SBIN},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000261#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000262#ifdef BB_SED
Erik Andersend75af992000-03-16 08:09:09 +0000263 {"sed", sed_main, _BB_DIR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000264#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000265#ifdef BB_SETKEYCODES
266 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
Erik Andersen3522eb12000-03-12 23:49:18 +0000267#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000268#ifdef BB_SH
269 {"sh", shell_main, _BB_DIR_BIN},
270#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000271#ifdef BB_SLEEP
Erik Andersend75af992000-03-16 08:09:09 +0000272 {"sleep", sleep_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000273#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000274#ifdef BB_SORT
Erik Andersend75af992000-03-16 08:09:09 +0000275 {"sort", sort_main, _BB_DIR_BIN},
John Beppu019513a1999-12-22 17:57:31 +0000276#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000277#ifdef BB_SYNC
Erik Andersend75af992000-03-16 08:09:09 +0000278 {"sync", sync_main, _BB_DIR_BIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000279#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000280#ifdef BB_SYSLOGD
Erik Andersend75af992000-03-16 08:09:09 +0000281 {"syslogd", syslogd_main, _BB_DIR_SBIN},
Eric Andersen3843e961999-11-25 07:30:46 +0000282#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000283#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000284 {"swapon", swap_on_off_main, _BB_DIR_SBIN},
285#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000286#ifdef BB_SWAPONOFF
Erik Andersend75af992000-03-16 08:09:09 +0000287 {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000288#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000289#ifdef BB_TAIL
Erik Andersend75af992000-03-16 08:09:09 +0000290 {"tail", tail_main, _BB_DIR_USR_BIN},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000291#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000292#ifdef BB_TAR
Erik Andersend75af992000-03-16 08:09:09 +0000293 {"tar", tar_main, _BB_DIR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000294#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000295#ifdef BB_TELNET
Erik Andersend75af992000-03-16 08:09:09 +0000296 {"telnet", telnet_main, _BB_DIR_USR_BIN},
297#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000298#ifdef BB_TEST
Erik Andersend75af992000-03-16 08:09:09 +0000299 {"test", test_main, _BB_DIR_USR_BIN},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000300#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000301#ifdef BB_TEE
Erik Andersend75af992000-03-16 08:09:09 +0000302 {"tee", tee_main, _BB_DIR_BIN},
John Beppu059f1521999-12-10 05:27:16 +0000303#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000304#ifdef BB_TOUCH
Erik Andersend75af992000-03-16 08:09:09 +0000305 {"touch", touch_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000306#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000307#ifdef BB_TR
Erik Andersend75af992000-03-16 08:09:09 +0000308 {"tr", tr_main, _BB_DIR_USR_BIN},
Erik Andersenfb002d02000-03-05 08:07:00 +0000309#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000310#ifdef BB_TRUE_FALSE
Erik Andersend75af992000-03-16 08:09:09 +0000311 {"true", true_main, _BB_DIR_BIN},
312#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000313#ifdef BB_TTY
Erik Andersend75af992000-03-16 08:09:09 +0000314 {"tty", tty_main, _BB_DIR_USR_BIN},
Erik Andersen05df2392000-01-13 04:43:48 +0000315#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000316#ifdef BB_UMOUNT
Erik Andersend75af992000-03-16 08:09:09 +0000317 {"umount", umount_main, _BB_DIR_BIN},
Erik Andersen66be5e72000-03-05 07:52:05 +0000318#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000319#ifdef BB_UNAME
Erik Andersend75af992000-03-16 08:09:09 +0000320 {"uname", uname_main, _BB_DIR_BIN},
Eric Andersen0460ff21999-10-25 23:32:44 +0000321#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000322#ifdef BB_UNIQ
Erik Andersena6c75222000-04-18 00:00:52 +0000323 {"uniq", uniq_main, _BB_DIR_USR_BIN},
John Beppuabb47722000-01-06 00:48:21 +0000324#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000325#ifdef BB_UPDATE
Erik Andersend75af992000-03-16 08:09:09 +0000326 {"update", update_main, _BB_DIR_SBIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000327#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000328#ifdef BB_UPTIME
329 {"uptime", uptime_main, _BB_DIR_USR_BIN},
330#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000331#ifdef BB_UUENCODE
332 {"uuencode", uuencode_main, _BB_DIR_USR_BIN},
333#endif
334#ifdef BB_UUDECODE
335 {"uudecode", uudecode_main, _BB_DIR_USR_BIN},
336#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000337#ifdef BB_USLEEP
338 {"usleep", usleep_main, _BB_DIR_BIN},
339#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000340#ifdef BB_WC
Erik Andersend75af992000-03-16 08:09:09 +0000341 {"wc", wc_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000342#endif
Erik Andersen330fd2b2000-05-19 05:35:19 +0000343#ifdef BB_WHICH
344 {"which", which_main, _BB_DIR_USR_BIN},
345#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000346#ifdef BB_WHOAMI
Erik Andersend75af992000-03-16 08:09:09 +0000347 {"whoami", whoami_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000348#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000349#ifdef BB_YES
Erik Andersend75af992000-03-16 08:09:09 +0000350 {"yes", yes_main, _BB_DIR_USR_BIN},
Erik Andersen31638212000-01-15 22:28:50 +0000351#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000352#ifdef BB_GUNZIP
Erik Andersend75af992000-03-16 08:09:09 +0000353 {"zcat", gunzip_main, _BB_DIR_BIN},
354#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000355#ifdef BB_TEST
356 {"[", test_main, _BB_DIR_USR_BIN},
Eric Andersencc8ed391999-10-05 16:24:54 +0000357#endif
Eric Andersend6912c92000-07-14 06:29:10 +0000358 {0,NULL,0}
Eric Andersencc8ed391999-10-05 16:24:54 +0000359};
360
Matt Kraai3ecbe9f2000-07-12 00:43:28 +0000361char *applet_name;
Erik Andersen05df2392000-01-13 04:43:48 +0000362
John Beppu8f425db2000-06-27 04:50:02 +0000363#ifdef BB_FEATURE_INSTALLER
364/*
365 * directory table
John Beppueb028332000-06-28 00:55:31 +0000366 * this should be consistent w/ the enum, internal.h::Location,
367 * or else...
John Beppu8f425db2000-06-27 04:50:02 +0000368 */
369static char* install_dir[] = {
John Beppueb028332000-06-28 00:55:31 +0000370 "/",
371 "/bin",
372 "/sbin",
373 "/usr/bin",
374 "/usr/sbin",
John Beppu8f425db2000-06-27 04:50:02 +0000375};
376
377/* abstract link() */
378typedef int (*__link_f)(const char *, const char *);
379
John Beppu7cdc76d2000-06-28 00:41:26 +0000380/*
381 * Where in the filesystem is this busybox?
382 * [return]
383 * malloc'd string w/ full pathname of busybox's location
384 * NULL on failure
385 */
386static char *busybox_fullpath()
387{
John Beppueb028332000-06-28 00:55:31 +0000388 pid_t pid;
389 char path[256];
390 char proc[256];
391 int len;
John Beppu7cdc76d2000-06-28 00:41:26 +0000392
393 pid = getpid();
394 sprintf(proc, "/proc/%d/exe", pid);
395 len = readlink(proc, path, 256);
396 if (len != -1) {
397 path[len] = 0;
398 } else {
Matt Kraaid537a952000-07-14 01:51:25 +0000399 errorMsg("%s: %s\n", proc, strerror(errno));
John Beppu7cdc76d2000-06-28 00:41:26 +0000400 return NULL;
401 }
402 return strdup(path);
403}
404
John Beppu8f425db2000-06-27 04:50:02 +0000405/* create (sym)links for each applet */
John Beppu495869f2000-06-27 07:54:33 +0000406static int install_links(const char *busybox, int use_symbolic_links)
John Beppu8f425db2000-06-27 04:50:02 +0000407{
John Beppueb028332000-06-28 00:55:31 +0000408 __link_f Link = link;
John Beppu8f425db2000-06-27 04:50:02 +0000409
John Beppueb028332000-06-28 00:55:31 +0000410 char command[256];
411 int i;
412 int rc = 0;
John Beppu8f425db2000-06-27 04:50:02 +0000413
414 if (use_symbolic_links) Link = symlink;
415
John Beppueb028332000-06-28 00:55:31 +0000416 for (i = 0; applets[i].name != NULL; i++) {
417 sprintf (
John Beppu8f425db2000-06-27 04:50:02 +0000418 command,
419 "%s/%s",
420 install_dir[applets[i].location],
421 applets[i].name
422 );
John Beppu7cdc76d2000-06-28 00:41:26 +0000423#if 1
John Beppueb028332000-06-28 00:55:31 +0000424 rc |= Link(busybox, command);
John Beppu8f425db2000-06-27 04:50:02 +0000425#else
John Beppueb028332000-06-28 00:55:31 +0000426 puts(command);
John Beppu8f425db2000-06-27 04:50:02 +0000427#endif
428 if (rc) {
Matt Kraaid537a952000-07-14 01:51:25 +0000429 errorMsg("%s: %s\n", command, strerror(errno));
John Beppu8f425db2000-06-27 04:50:02 +0000430 }
John Beppueb028332000-06-28 00:55:31 +0000431 }
John Beppu8f425db2000-06-27 04:50:02 +0000432 return rc;
433}
434
435#if 0
436int uninstall_links() ?
437#endif
438#endif /* BB_FEATURE_INSTALLER */
439
Erik Andersen05df2392000-01-13 04:43:48 +0000440
Eric Andersencc8ed391999-10-05 16:24:54 +0000441int main(int argc, char **argv)
442{
Erik Andersend75af992000-03-16 08:09:09 +0000443 char *s;
Erik Andersenbcd61772000-05-13 06:33:19 +0000444 const struct BB_applet *a = applets;
Matt Kraaid537a952000-07-14 01:51:25 +0000445 applet_name = "busybox";
Eric Andersencc8ed391999-10-05 16:24:54 +0000446
John Beppu8f425db2000-06-27 04:50:02 +0000447#ifdef BB_FEATURE_INSTALLER
John Beppu27b59242000-06-27 04:56:45 +0000448 /*
449 * This style of argument parsing doesn't scale well
450 * in the event that busybox starts wanting more --options.
451 * If someone has a cleaner approach, by all means implement it.
452 */
John Beppu8f425db2000-06-27 04:50:02 +0000453 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
454 int use_symbolic_links = 0;
John Beppu7cdc76d2000-06-28 00:41:26 +0000455 int rc = 0;
456 char *busybox;
John Beppu8f425db2000-06-27 04:50:02 +0000457
John Beppu27b59242000-06-27 04:56:45 +0000458 /* to use symlinks, or not to use symlinks... */
John Beppu8f425db2000-06-27 04:50:02 +0000459 if (argc > 2) {
460 if ((strcmp(argv[2], "-s") == 0)) {
461 use_symbolic_links = 1;
462 }
463 }
John Beppu7cdc76d2000-06-28 00:41:26 +0000464
465 /* link */
466 busybox = busybox_fullpath();
467 if (busybox) {
468 install_links(busybox, use_symbolic_links);
469 free(busybox);
470 } else {
471 rc = 1;
472 }
473 return rc;
John Beppu8f425db2000-06-27 04:50:02 +0000474 }
475#endif /* BB_FEATURE_INSTALLER */
476
Matt Kraai77190082000-07-11 20:03:24 +0000477 for (s = applet_name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000478 if (*s++ == '/')
Matt Kraai77190082000-07-11 20:03:24 +0000479 applet_name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000480 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000481
Matt Kraai77190082000-07-11 20:03:24 +0000482 *argv = applet_name;
Erik Andersen029011b2000-03-04 21:19:32 +0000483
Eric Andersen5d41d602000-06-29 20:20:14 +0000484#ifdef BB_SH
485 /* Add in a special case hack -- whenever **argv == '-'
486 * (i.e. '-su' or '-sh') always invoke the shell */
487 if (**argv == '-')
488 exit(((*(shell_main)) (argc, argv)));
489#endif
490
Erik Andersene49d5ec2000-02-08 19:58:47 +0000491 while (a->name != 0) {
Matt Kraai77190082000-07-11 20:03:24 +0000492 if (strcmp(applet_name, a->name) == 0) {
Eric Andersenb6106152000-06-19 17:25:40 +0000493 exit(((*(a->main)) (argc, argv)));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000494 }
495 a++;
496 }
Eric Andersenb6106152000-06-19 17:25:40 +0000497 return(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000498}
499
500
501int busybox_main(int argc, char **argv)
502{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000503 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000504
Erik Andersene49d5ec2000-02-08 19:58:47 +0000505 argc--;
506 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000507
Erik Andersene49d5ec2000-02-08 19:58:47 +0000508 if (been_there_done_that == 1 || argc < 1) {
Erik Andersenbcd61772000-05-13 06:33:19 +0000509 const struct BB_applet *a = applets;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000510
Pavel Roskin9c5fcc32000-07-17 23:45:12 +0000511 fprintf(stderr, "%s\n\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000512 "Usage: busybox [function] [arguments]...\n"
513 " or: [function] [arguments]...\n\n"
John Beppub4f86062000-04-13 03:36:01 +0000514 "\tBusyBox is a multi-call binary that combines many common Unix\n"
515 "\tutilities into a single executable. Most people will create a\n"
516 "\tlink to busybox for each function they wish to use, and BusyBox\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000517 "\twill act like whatever it was invoked as.\n"
Pavel Roskin9c5fcc32000-07-17 23:45:12 +0000518 "\nCurrently defined functions:\n", full_version);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000519
520 while (a->name != 0) {
521 col +=
522 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
523 (a++)->name);
524 if (col > 60 && a->name != 0) {
525 fprintf(stderr, ",\n");
526 col = 0;
527 }
528 }
529 fprintf(stderr, "\n\n");
530 exit(-1);
Eric Andersencc8ed391999-10-05 16:24:54 +0000531 }
Eric Andersenb6106152000-06-19 17:25:40 +0000532 /* If we've already been here once, exit now */
533 been_there_done_that = 1;
534 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000535}
Erik Andersen029011b2000-03-04 21:19:32 +0000536
537/*
538Local Variables:
539c-file-style: "linux"
540c-basic-offset: 4
541tab-width: 4
542End:
543*/