blob: 17a4c447a849ddc0aa50f9714371f09b13250d1e [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 Andersenbcd61772000-05-13 06:33:19 +000013const struct BB_applet applets[] = {
Eric Andersencc8ed391999-10-05 16:24:54 +000014
Eric Andersen86ab8a32000-06-02 03:21:42 +000015#ifdef BB_AR
Matt Kraai27a80422000-07-19 19:24:01 +000016 {"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
Eric Andersen86ab8a32000-06-02 03:21:42 +000017#endif
Erik Andersen298854f2000-03-23 01:09:18 +000018#ifdef BB_BASENAME
Matt Kraai27a80422000-07-19 19:24:01 +000019 {"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
Erik Andersene2729152000-02-18 21:34:17 +000020#endif
Matt Kraai27a80422000-07-19 19:24:01 +000021 {"busybox", busybox_main, _BB_DIR_BIN, NULL},
Erik Andersen298854f2000-03-23 01:09:18 +000022#ifdef BB_CAT
Matt Kraai27a80422000-07-19 19:24:01 +000023 {"cat", cat_main, _BB_DIR_BIN, cat_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000024#endif
Erik Andersen298854f2000-03-23 01:09:18 +000025#ifdef BB_CHMOD_CHOWN_CHGRP
Matt Kraai27a80422000-07-19 19:24:01 +000026 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +000027#endif
28#ifdef BB_CHMOD_CHOWN_CHGRP
Matt Kraai27a80422000-07-19 19:24:01 +000029 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
Erik Andersend75af992000-03-16 08:09:09 +000030#endif
Erik Andersen298854f2000-03-23 01:09:18 +000031#ifdef BB_CHMOD_CHOWN_CHGRP
Matt Kraai27a80422000-07-19 19:24:01 +000032 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
Erik Andersend75af992000-03-16 08:09:09 +000033#endif
Erik Andersen298854f2000-03-23 01:09:18 +000034#ifdef BB_CHROOT
Eric Andersen88f50b62000-08-10 17:59:11 +000035 {"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000036#endif
Erik Andersen298854f2000-03-23 01:09:18 +000037#ifdef BB_CLEAR
Matt Kraai27a80422000-07-19 19:24:01 +000038 {"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000039#endif
Erik Andersen298854f2000-03-23 01:09:18 +000040#ifdef BB_CHVT
Matt Kraai27a80422000-07-19 19:24:01 +000041 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
Eric Andersenabc0f4f1999-12-08 23:19:36 +000042#endif
Erik Andersen298854f2000-03-23 01:09:18 +000043#ifdef BB_CP_MV
Matt Kraai27a80422000-07-19 19:24:01 +000044 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
Erik Andersend75af992000-03-16 08:09:09 +000045#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000046#ifdef BB_CUT
Matt Kraai27a80422000-07-19 19:24:01 +000047 {"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000048#endif
Erik Andersen298854f2000-03-23 01:09:18 +000049#ifdef BB_DATE
Matt Kraai27a80422000-07-19 19:24:01 +000050 {"date", date_main, _BB_DIR_BIN, date_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000051#endif
John Beppu00216792000-06-21 19:06:16 +000052#ifdef BB_DC
Matt Kraai27a80422000-07-19 19:24:01 +000053 {"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
John Beppu00216792000-06-21 19:06:16 +000054#endif
Erik Andersen298854f2000-03-23 01:09:18 +000055#ifdef BB_DD
Matt Kraai27a80422000-07-19 19:24:01 +000056 {"dd", dd_main, _BB_DIR_BIN, dd_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000057#endif
Erik Andersen298854f2000-03-23 01:09:18 +000058#ifdef BB_DF
Matt Kraai27a80422000-07-19 19:24:01 +000059 {"df", df_main, _BB_DIR_BIN, df_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000060#endif
Erik Andersen298854f2000-03-23 01:09:18 +000061#ifdef BB_DIRNAME
Matt Kraai27a80422000-07-19 19:24:01 +000062 {"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
Erik Andersenfb002d02000-03-05 08:07:00 +000063#endif
Erik Andersen298854f2000-03-23 01:09:18 +000064#ifdef BB_DMESG
Matt Kraai27a80422000-07-19 19:24:01 +000065 {"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000066#endif
Eric Andersencff3fe32000-09-20 19:22:26 +000067#ifdef BB_DOS2UNIX
68 {"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
69#endif
Erik Andersen298854f2000-03-23 01:09:18 +000070#ifdef BB_DU
Eric Andersen88f50b62000-08-10 17:59:11 +000071 {"du", du_main, _BB_DIR_USR_BIN, du_usage},
John Beppu7a986061999-12-09 18:29:29 +000072#endif
Eric Andersen61dc0572000-07-11 17:29:36 +000073#ifdef BB_DUMPKMAP
Matt Kraai27a80422000-07-19 19:24:01 +000074 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
Eric Andersen61dc0572000-07-11 17:29:36 +000075#endif
Erik Andersen298854f2000-03-23 01:09:18 +000076#ifdef BB_DUTMP
Matt Kraai27a80422000-07-19 19:24:01 +000077 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
Erik Andersend75af992000-03-16 08:09:09 +000078#endif
Erik Andersen298854f2000-03-23 01:09:18 +000079#ifdef BB_ECHO
Matt Kraai27a80422000-07-19 19:24:01 +000080 {"echo", echo_main, _BB_DIR_BIN, echo_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000081#endif
Eric Andersen1b355eb2000-09-05 17:37:48 +000082#ifdef BB_EXPR
83 {"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
84#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +000085#ifdef BB_TRUE_FALSE
Matt Kraai27a80422000-07-19 19:24:01 +000086 {"false", false_main, _BB_DIR_BIN, false_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +000087#endif
Erik Andersen298854f2000-03-23 01:09:18 +000088#ifdef BB_FBSET
Matt Kraai27a80422000-07-19 19:24:01 +000089 {"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
Erik Andersen1c5b2581999-12-16 20:59:36 +000090#endif
Erik Andersen298854f2000-03-23 01:09:18 +000091#ifdef BB_FDFLUSH
Matt Kraai27a80422000-07-19 19:24:01 +000092 {"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000093#endif
Erik Andersen298854f2000-03-23 01:09:18 +000094#ifdef BB_FIND
Matt Kraai27a80422000-07-19 19:24:01 +000095 {"find", find_main, _BB_DIR_USR_BIN, find_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000096#endif
Erik Andersen298854f2000-03-23 01:09:18 +000097#ifdef BB_FREE
Matt Kraai27a80422000-07-19 19:24:01 +000098 {"free", free_main, _BB_DIR_USR_BIN, free_usage},
Eric Andersen0460ff21999-10-25 23:32:44 +000099#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000100#ifdef BB_FREERAMDISK
Matt Kraai27a80422000-07-19 19:24:01 +0000101 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
Erik Andersen64371702000-03-04 22:23:27 +0000102#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000103#ifdef BB_DEALLOCVT
Matt Kraai27a80422000-07-19 19:24:01 +0000104 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
Eric Andersen0460ff21999-10-25 23:32:44 +0000105#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000106#ifdef BB_FSCK_MINIX
Matt Kraai27a80422000-07-19 19:24:01 +0000107 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
Eric Andersene494fdd1999-10-19 20:23:03 +0000108#endif
Eric Andersena1f16bb2000-08-21 22:02:34 +0000109#ifdef BB_GETOPT
110 {"getopt", getopt_main, _BB_DIR_BIN},
111#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000112#ifdef BB_GREP
Matt Kraai27a80422000-07-19 19:24:01 +0000113 {"grep", grep_main, _BB_DIR_BIN, grep_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000114#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000115#ifdef BB_GUNZIP
Matt Kraai27a80422000-07-19 19:24:01 +0000116 {"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000117#endif
118#ifdef BB_GZIP
Matt Kraai27a80422000-07-19 19:24:01 +0000119 {"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000120#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000121#ifdef BB_HALT
Matt Kraai27a80422000-07-19 19:24:01 +0000122 {"halt", halt_main, _BB_DIR_SBIN, halt_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000123#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000124#ifdef BB_HEAD
Matt Kraai27a80422000-07-19 19:24:01 +0000125 {"head", head_main, _BB_DIR_USR_BIN, head_usage},
John Beppu3157b1f1999-12-10 07:42:50 +0000126#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000127#ifdef BB_HOSTID
Matt Kraai27a80422000-07-19 19:24:01 +0000128 {"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000129#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000130#ifdef BB_HOSTNAME
Matt Kraai27a80422000-07-19 19:24:01 +0000131 {"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
Eric Andersen485b9551999-12-07 23:14:59 +0000132#endif
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000133#ifdef BB_ID
Matt Kraai27a80422000-07-19 19:24:01 +0000134 {"id", id_main, _BB_DIR_USR_BIN, id_usage},
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000135#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000136#ifdef BB_INIT
Matt Kraai27a80422000-07-19 19:24:01 +0000137 {"init", init_main, _BB_DIR_SBIN, NULL},
Eric Andersencc8ed391999-10-05 16:24:54 +0000138#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000139#ifdef BB_INSMOD
Matt Kraai27a80422000-07-19 19:24:01 +0000140 {"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000141#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000142#ifdef BB_KILL
Matt Kraai27a80422000-07-19 19:24:01 +0000143 {"kill", kill_main, _BB_DIR_BIN, kill_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000144#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000145#ifdef BB_KILLALL
Matt Kraai27a80422000-07-19 19:24:01 +0000146 {"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000147#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000148#ifdef BB_LENGTH
Matt Kraai27a80422000-07-19 19:24:01 +0000149 {"length", length_main, _BB_DIR_USR_BIN, length_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000150#endif
Erik Andersen9a8195c2000-04-18 23:32:10 +0000151#ifdef BB_LINUXRC
Eric Andersencb91d692000-09-01 18:43:02 +0000152 {"linuxrc", init_main, _BB_DIR_ROOT, NULL},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000153#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000154#ifdef BB_LN
Matt Kraai27a80422000-07-19 19:24:01 +0000155 {"ln", ln_main, _BB_DIR_BIN, ln_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000156#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000157#ifdef BB_LOADACM
Matt Kraai27a80422000-07-19 19:24:01 +0000158 {"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000159#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000160#ifdef BB_LOADFONT
Matt Kraai27a80422000-07-19 19:24:01 +0000161 {"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000162#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000163#ifdef BB_LOADKMAP
Matt Kraai27a80422000-07-19 19:24:01 +0000164 {"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000165#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000166#ifdef BB_LOGGER
Matt Kraai27a80422000-07-19 19:24:01 +0000167 {"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000168#endif
169#ifdef BB_LOGNAME
Matt Kraai27a80422000-07-19 19:24:01 +0000170 {"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000171#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000172#ifdef BB_LS
Matt Kraai27a80422000-07-19 19:24:01 +0000173 {"ls", ls_main, _BB_DIR_BIN, ls_usage},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000174#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000175#ifdef BB_LSMOD
Matt Kraai27a80422000-07-19 19:24:01 +0000176 {"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000177#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000178#ifdef BB_MAKEDEVS
Matt Kraai27a80422000-07-19 19:24:01 +0000179 {"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000180#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000181#ifdef BB_MD5SUM
Matt Kraai27a80422000-07-19 19:24:01 +0000182 {"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000183#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000184#ifdef BB_MKDIR
Matt Kraai27a80422000-07-19 19:24:01 +0000185 {"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000186#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000187#ifdef BB_MKFIFO
Matt Kraai27a80422000-07-19 19:24:01 +0000188 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
Eric Andersen19db07b1999-12-11 08:41:28 +0000189#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000190#ifdef BB_MKFS_MINIX
Matt Kraai27a80422000-07-19 19:24:01 +0000191 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000192#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000193#ifdef BB_MKNOD
Matt Kraai27a80422000-07-19 19:24:01 +0000194 {"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000195#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000196#ifdef BB_MKSWAP
Matt Kraai27a80422000-07-19 19:24:01 +0000197 {"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000198#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000199#ifdef BB_MKTEMP
Matt Kraai27a80422000-07-19 19:24:01 +0000200 {"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
Erik Andersen227a59b2000-04-25 23:24:55 +0000201#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000202#ifdef BB_NC
Matt Kraai27a80422000-07-19 19:24:01 +0000203 {"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000204#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000205#ifdef BB_MORE
Matt Kraai27a80422000-07-19 19:24:01 +0000206 {"more", more_main, _BB_DIR_BIN, more_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000207#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000208#ifdef BB_MOUNT
Matt Kraai27a80422000-07-19 19:24:01 +0000209 {"mount", mount_main, _BB_DIR_BIN, mount_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000210#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000211#ifdef BB_MT
Matt Kraai27a80422000-07-19 19:24:01 +0000212 {"mt", mt_main, _BB_DIR_BIN, mt_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000213#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000214#ifdef BB_CP_MV
Matt Kraai27a80422000-07-19 19:24:01 +0000215 {"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000216#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000217#ifdef BB_NSLOOKUP
Matt Kraai27a80422000-07-19 19:24:01 +0000218 {"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
John Beppub332e772000-01-29 12:59:01 +0000219#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000220#ifdef BB_PING
Matt Kraai27a80422000-07-19 19:24:01 +0000221 {"ping", ping_main, _BB_DIR_BIN, ping_usage},
Eric Andersen485b9551999-12-07 23:14:59 +0000222#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000223#ifdef BB_POWEROFF
Matt Kraai27a80422000-07-19 19:24:01 +0000224 {"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
Eric Andersen2cb55071999-12-10 08:25:07 +0000225#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000226#ifdef BB_PRINTF
Matt Kraai27a80422000-07-19 19:24:01 +0000227 {"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000228#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000229#ifdef BB_PS
Matt Kraai27a80422000-07-19 19:24:01 +0000230 {"ps", ps_main, _BB_DIR_BIN, ps_usage},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000231#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000232#ifdef BB_PWD
Matt Kraai27a80422000-07-19 19:24:01 +0000233 {"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000234#endif
Eric Andersen918507e2000-08-21 22:46:33 +0000235#ifdef BB_RDATE
236 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
237#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000238#ifdef BB_REBOOT
Matt Kraai27a80422000-07-19 19:24:01 +0000239 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000240#endif
Eric Andersenbf960f52000-07-21 21:32:12 +0000241#ifdef BB_RENICE
242 {"renice", renice_main, _BB_DIR_USR_BIN},
243#endif
Eric Andersenfa405d02000-08-21 21:18:52 +0000244#ifdef BB_RESET
245 {"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
246#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000247#ifdef BB_RM
Matt Kraai27a80422000-07-19 19:24:01 +0000248 {"rm", rm_main, _BB_DIR_BIN, rm_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000249#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000250#ifdef BB_RMDIR
Matt Kraai27a80422000-07-19 19:24:01 +0000251 {"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000252#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000253#ifdef BB_RMMOD
Matt Kraai27a80422000-07-19 19:24:01 +0000254 {"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000255#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000256#ifdef BB_SED
Matt Kraai27a80422000-07-19 19:24:01 +0000257 {"sed", sed_main, _BB_DIR_BIN, sed_usage},
Erik Andersen3522eb12000-03-12 23:49:18 +0000258#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000259#ifdef BB_SETKEYCODES
Matt Kraai27a80422000-07-19 19:24:01 +0000260 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
Erik Andersen3522eb12000-03-12 23:49:18 +0000261#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000262#ifdef BB_SH
Matt Kraai27a80422000-07-19 19:24:01 +0000263 {"sh", shell_main, _BB_DIR_BIN, shell_usage},
Erik Andersen4f3f7572000-04-28 00:18:56 +0000264#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000265#ifdef BB_SLEEP
Matt Kraai27a80422000-07-19 19:24:01 +0000266 {"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000267#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000268#ifdef BB_SORT
Eric Andersen88f50b62000-08-10 17:59:11 +0000269 {"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
John Beppu019513a1999-12-22 17:57:31 +0000270#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000271#ifdef BB_SYNC
Matt Kraai27a80422000-07-19 19:24:01 +0000272 {"sync", sync_main, _BB_DIR_BIN, sync_usage},
Eric Andersen3843e961999-11-25 07:30:46 +0000273#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000274#ifdef BB_SYSLOGD
Matt Kraai27a80422000-07-19 19:24:01 +0000275 {"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
Eric Andersen3843e961999-11-25 07:30:46 +0000276#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000277#ifdef BB_SWAPONOFF
Matt Kraai27a80422000-07-19 19:24:01 +0000278 {"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000279#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000280#ifdef BB_SWAPONOFF
Matt Kraai27a80422000-07-19 19:24:01 +0000281 {"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000282#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000283#ifdef BB_TAIL
Matt Kraai27a80422000-07-19 19:24:01 +0000284 {"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000285#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000286#ifdef BB_TAR
Matt Kraai27a80422000-07-19 19:24:01 +0000287 {"tar", tar_main, _BB_DIR_BIN, tar_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000288#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000289#ifdef BB_TELNET
Matt Kraai27a80422000-07-19 19:24:01 +0000290 {"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000291#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000292#ifdef BB_TEST
Matt Kraai27a80422000-07-19 19:24:01 +0000293 {"test", test_main, _BB_DIR_USR_BIN, test_usage},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000294#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000295#ifdef BB_TEE
Eric Andersen88f50b62000-08-10 17:59:11 +0000296 {"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
John Beppu059f1521999-12-10 05:27:16 +0000297#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000298#ifdef BB_TOUCH
Eric Andersene89267c2000-08-19 20:16:16 +0000299 {"touch", touch_main, _BB_DIR_BIN, touch_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000300#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000301#ifdef BB_TR
Matt Kraai27a80422000-07-19 19:24:01 +0000302 {"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
Erik Andersenfb002d02000-03-05 08:07:00 +0000303#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000304#ifdef BB_TRUE_FALSE
Matt Kraai27a80422000-07-19 19:24:01 +0000305 {"true", true_main, _BB_DIR_BIN, true_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000306#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000307#ifdef BB_TTY
Matt Kraai27a80422000-07-19 19:24:01 +0000308 {"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
Erik Andersen05df2392000-01-13 04:43:48 +0000309#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000310#ifdef BB_UMOUNT
Matt Kraai27a80422000-07-19 19:24:01 +0000311 {"umount", umount_main, _BB_DIR_BIN, umount_usage},
Erik Andersen66be5e72000-03-05 07:52:05 +0000312#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000313#ifdef BB_UNAME
Matt Kraai27a80422000-07-19 19:24:01 +0000314 {"uname", uname_main, _BB_DIR_BIN, uname_usage},
Eric Andersen0460ff21999-10-25 23:32:44 +0000315#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000316#ifdef BB_UNIQ
Matt Kraai27a80422000-07-19 19:24:01 +0000317 {"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
John Beppuabb47722000-01-06 00:48:21 +0000318#endif
Eric Andersencff3fe32000-09-20 19:22:26 +0000319#ifdef BB_UNIX2DOS
320 {"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
321#endif
322#ifdef BB_UNRPM
323 {"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
324#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000325#ifdef BB_UPDATE
Matt Kraai27a80422000-07-19 19:24:01 +0000326 {"update", update_main, _BB_DIR_SBIN, update_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000327#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000328#ifdef BB_UPTIME
Matt Kraai27a80422000-07-19 19:24:01 +0000329 {"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000330#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000331#ifdef BB_UUENCODE
Matt Kraai27a80422000-07-19 19:24:01 +0000332 {"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000333#endif
334#ifdef BB_UUDECODE
Matt Kraai27a80422000-07-19 19:24:01 +0000335 {"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000336#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000337#ifdef BB_USLEEP
Matt Kraai27a80422000-07-19 19:24:01 +0000338 {"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
Erik Andersenb99ca132000-04-04 18:49:18 +0000339#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000340#ifdef BB_WC
Matt Kraai27a80422000-07-19 19:24:01 +0000341 {"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000342#endif
Eric Andersen96700832000-09-04 15:15:55 +0000343#ifdef BB_WGET
344 {"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
345#endif
Erik Andersen330fd2b2000-05-19 05:35:19 +0000346#ifdef BB_WHICH
Matt Kraai27a80422000-07-19 19:24:01 +0000347 {"which", which_main, _BB_DIR_USR_BIN, which_usage},
Erik Andersen330fd2b2000-05-19 05:35:19 +0000348#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000349#ifdef BB_WHOAMI
Matt Kraai27a80422000-07-19 19:24:01 +0000350 {"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000351#endif
Eric Andersen92a61c12000-09-22 20:01:23 +0000352#ifdef BB_XARGS
353 {"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
354#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000355#ifdef BB_YES
Matt Kraai27a80422000-07-19 19:24:01 +0000356 {"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000357#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000358#ifdef BB_GUNZIP
Matt Kraai27a80422000-07-19 19:24:01 +0000359 {"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000360#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000361#ifdef BB_TEST
Matt Kraai27a80422000-07-19 19:24:01 +0000362 {"[", test_main, _BB_DIR_USR_BIN, test_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000363#endif
Matt Kraai27a80422000-07-19 19:24:01 +0000364 {0,NULL,0,NULL}
Eric Andersencc8ed391999-10-05 16:24:54 +0000365};
366
Eric Andersen501c88b2000-07-28 15:14:45 +0000367const char *applet_name;
Erik Andersen05df2392000-01-13 04:43:48 +0000368
John Beppu8f425db2000-06-27 04:50:02 +0000369#ifdef BB_FEATURE_INSTALLER
370/*
371 * directory table
John Beppueb028332000-06-28 00:55:31 +0000372 * this should be consistent w/ the enum, internal.h::Location,
373 * or else...
John Beppu8f425db2000-06-27 04:50:02 +0000374 */
375static char* install_dir[] = {
John Beppueb028332000-06-28 00:55:31 +0000376 "/",
377 "/bin",
378 "/sbin",
379 "/usr/bin",
380 "/usr/sbin",
John Beppu8f425db2000-06-27 04:50:02 +0000381};
382
383/* abstract link() */
384typedef int (*__link_f)(const char *, const char *);
385
John Beppu7cdc76d2000-06-28 00:41:26 +0000386/*
387 * Where in the filesystem is this busybox?
388 * [return]
389 * malloc'd string w/ full pathname of busybox's location
390 * NULL on failure
391 */
392static char *busybox_fullpath()
393{
John Beppueb028332000-06-28 00:55:31 +0000394 pid_t pid;
395 char path[256];
396 char proc[256];
397 int len;
John Beppu7cdc76d2000-06-28 00:41:26 +0000398
399 pid = getpid();
400 sprintf(proc, "/proc/%d/exe", pid);
401 len = readlink(proc, path, 256);
402 if (len != -1) {
403 path[len] = 0;
404 } else {
Matt Kraaid537a952000-07-14 01:51:25 +0000405 errorMsg("%s: %s\n", proc, strerror(errno));
John Beppu7cdc76d2000-06-28 00:41:26 +0000406 return NULL;
407 }
408 return strdup(path);
409}
410
John Beppu8f425db2000-06-27 04:50:02 +0000411/* create (sym)links for each applet */
Eric Andersenc5949f62000-09-25 20:35:54 +0000412static void install_links(const char *busybox, int use_symbolic_links)
John Beppu8f425db2000-06-27 04:50:02 +0000413{
John Beppueb028332000-06-28 00:55:31 +0000414 __link_f Link = link;
John Beppu8f425db2000-06-27 04:50:02 +0000415
John Beppueb028332000-06-28 00:55:31 +0000416 char command[256];
417 int i;
Eric Andersenc5949f62000-09-25 20:35:54 +0000418 int rc;
John Beppu8f425db2000-06-27 04:50:02 +0000419
420 if (use_symbolic_links) Link = symlink;
421
John Beppueb028332000-06-28 00:55:31 +0000422 for (i = 0; applets[i].name != NULL; i++) {
Eric Andersenc5949f62000-09-25 20:35:54 +0000423 sprintf ( command, "%s/%s",
424 install_dir[applets[i].location],
425 applets[i].name);
426 rc = Link(busybox, command);
427
John Beppu8f425db2000-06-27 04:50:02 +0000428 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}
433
John Beppu8f425db2000-06-27 04:50:02 +0000434#endif /* BB_FEATURE_INSTALLER */
435
Erik Andersen05df2392000-01-13 04:43:48 +0000436
Eric Andersencc8ed391999-10-05 16:24:54 +0000437int main(int argc, char **argv)
438{
Eric Andersen501c88b2000-07-28 15:14:45 +0000439 const char *s;
Erik Andersenbcd61772000-05-13 06:33:19 +0000440 const struct BB_applet *a = applets;
Matt Kraaid537a952000-07-14 01:51:25 +0000441 applet_name = "busybox";
Eric Andersencc8ed391999-10-05 16:24:54 +0000442
John Beppu8f425db2000-06-27 04:50:02 +0000443#ifdef BB_FEATURE_INSTALLER
John Beppu27b59242000-06-27 04:56:45 +0000444 /*
445 * This style of argument parsing doesn't scale well
446 * in the event that busybox starts wanting more --options.
447 * If someone has a cleaner approach, by all means implement it.
448 */
John Beppu8f425db2000-06-27 04:50:02 +0000449 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
450 int use_symbolic_links = 0;
John Beppu7cdc76d2000-06-28 00:41:26 +0000451 int rc = 0;
452 char *busybox;
John Beppu8f425db2000-06-27 04:50:02 +0000453
John Beppu27b59242000-06-27 04:56:45 +0000454 /* to use symlinks, or not to use symlinks... */
John Beppu8f425db2000-06-27 04:50:02 +0000455 if (argc > 2) {
456 if ((strcmp(argv[2], "-s") == 0)) {
457 use_symbolic_links = 1;
458 }
459 }
John Beppu7cdc76d2000-06-28 00:41:26 +0000460
461 /* link */
462 busybox = busybox_fullpath();
463 if (busybox) {
464 install_links(busybox, use_symbolic_links);
465 free(busybox);
466 } else {
467 rc = 1;
468 }
469 return rc;
John Beppu8f425db2000-06-27 04:50:02 +0000470 }
471#endif /* BB_FEATURE_INSTALLER */
472
Matt Kraai77190082000-07-11 20:03:24 +0000473 for (s = applet_name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000474 if (*s++ == '/')
Matt Kraai77190082000-07-11 20:03:24 +0000475 applet_name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000476 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000477
Eric Andersen501c88b2000-07-28 15:14:45 +0000478 *argv = (char*)applet_name;
Erik Andersen029011b2000-03-04 21:19:32 +0000479
Eric Andersen5d41d602000-06-29 20:20:14 +0000480#ifdef BB_SH
481 /* Add in a special case hack -- whenever **argv == '-'
482 * (i.e. '-su' or '-sh') always invoke the shell */
Eric Andersenbf960f52000-07-21 21:32:12 +0000483 if (**argv == '-' && *(*argv+1)!= '-') {
Eric Andersen5d41d602000-06-29 20:20:14 +0000484 exit(((*(shell_main)) (argc, argv)));
Eric Andersenbf960f52000-07-21 21:32:12 +0000485 }
Eric Andersen5d41d602000-06-29 20:20:14 +0000486#endif
487
Erik Andersene49d5ec2000-02-08 19:58:47 +0000488 while (a->name != 0) {
Matt Kraai77190082000-07-11 20:03:24 +0000489 if (strcmp(applet_name, a->name) == 0) {
Matt Kraai27a80422000-07-19 19:24:01 +0000490 if (a->usage && argv[1] && strcmp(argv[1], "--help") == 0)
491 usage(a->usage);
Eric Andersenb6106152000-06-19 17:25:40 +0000492 exit(((*(a->main)) (argc, argv)));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000493 }
494 a++;
495 }
Eric Andersenb6106152000-06-19 17:25:40 +0000496 return(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000497}
498
499
500int busybox_main(int argc, char **argv)
501{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000502 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000503
Erik Andersene49d5ec2000-02-08 19:58:47 +0000504 argc--;
505 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000506
Erik Andersene49d5ec2000-02-08 19:58:47 +0000507 if (been_there_done_that == 1 || argc < 1) {
Erik Andersenbcd61772000-05-13 06:33:19 +0000508 const struct BB_applet *a = applets;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000509
Pavel Roskin9c5fcc32000-07-17 23:45:12 +0000510 fprintf(stderr, "%s\n\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000511 "Usage: busybox [function] [arguments]...\n"
512 " or: [function] [arguments]...\n\n"
John Beppub4f86062000-04-13 03:36:01 +0000513 "\tBusyBox is a multi-call binary that combines many common Unix\n"
514 "\tutilities into a single executable. Most people will create a\n"
515 "\tlink to busybox for each function they wish to use, and BusyBox\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000516 "\twill act like whatever it was invoked as.\n"
Pavel Roskin9c5fcc32000-07-17 23:45:12 +0000517 "\nCurrently defined functions:\n", full_version);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000518
519 while (a->name != 0) {
520 col +=
521 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
522 (a++)->name);
523 if (col > 60 && a->name != 0) {
524 fprintf(stderr, ",\n");
525 col = 0;
526 }
527 }
528 fprintf(stderr, "\n\n");
529 exit(-1);
Eric Andersencc8ed391999-10-05 16:24:54 +0000530 }
Eric Andersenb6106152000-06-19 17:25:40 +0000531 /* If we've already been here once, exit now */
532 been_there_done_that = 1;
533 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000534}
Erik Andersen029011b2000-03-04 21:19:32 +0000535
536/*
537Local Variables:
538c-file-style: "linux"
539c-basic-offset: 4
540tab-width: 4
541End:
542*/