blob: 1ed44ed9b692bd6bdfb6e6158f33171dbc938a7e [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
Matt Kraai27a80422000-07-19 19:24:01 +000035 {"chroot", chroot_main, _BB_DIR_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
Erik Andersen298854f2000-03-23 01:09:18 +000067#ifdef BB_DU
Matt Kraai27a80422000-07-19 19:24:01 +000068 {"du", du_main, _BB_DIR_BIN, du_usage},
John Beppu7a986061999-12-09 18:29:29 +000069#endif
Eric Andersen61dc0572000-07-11 17:29:36 +000070#ifdef BB_DUMPKMAP
Matt Kraai27a80422000-07-19 19:24:01 +000071 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
Eric Andersen61dc0572000-07-11 17:29:36 +000072#endif
Erik Andersen298854f2000-03-23 01:09:18 +000073#ifdef BB_DUTMP
Matt Kraai27a80422000-07-19 19:24:01 +000074 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
Erik Andersend75af992000-03-16 08:09:09 +000075#endif
Erik Andersen298854f2000-03-23 01:09:18 +000076#ifdef BB_ECHO
Matt Kraai27a80422000-07-19 19:24:01 +000077 {"echo", echo_main, _BB_DIR_BIN, echo_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000078#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +000079#ifdef BB_TRUE_FALSE
Matt Kraai27a80422000-07-19 19:24:01 +000080 {"false", false_main, _BB_DIR_BIN, false_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +000081#endif
Erik Andersen298854f2000-03-23 01:09:18 +000082#ifdef BB_FBSET
Matt Kraai27a80422000-07-19 19:24:01 +000083 {"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
Erik Andersen1c5b2581999-12-16 20:59:36 +000084#endif
Erik Andersen298854f2000-03-23 01:09:18 +000085#ifdef BB_FDFLUSH
Matt Kraai27a80422000-07-19 19:24:01 +000086 {"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000087#endif
Erik Andersen298854f2000-03-23 01:09:18 +000088#ifdef BB_FIND
Matt Kraai27a80422000-07-19 19:24:01 +000089 {"find", find_main, _BB_DIR_USR_BIN, find_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +000090#endif
Erik Andersen298854f2000-03-23 01:09:18 +000091#ifdef BB_FREE
Matt Kraai27a80422000-07-19 19:24:01 +000092 {"free", free_main, _BB_DIR_USR_BIN, free_usage},
Eric Andersen0460ff21999-10-25 23:32:44 +000093#endif
Erik Andersen298854f2000-03-23 01:09:18 +000094#ifdef BB_FREERAMDISK
Matt Kraai27a80422000-07-19 19:24:01 +000095 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
Erik Andersen64371702000-03-04 22:23:27 +000096#endif
Erik Andersen298854f2000-03-23 01:09:18 +000097#ifdef BB_DEALLOCVT
Matt Kraai27a80422000-07-19 19:24:01 +000098 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
Eric Andersen0460ff21999-10-25 23:32:44 +000099#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000100#ifdef BB_FSCK_MINIX
Matt Kraai27a80422000-07-19 19:24:01 +0000101 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
Eric Andersene494fdd1999-10-19 20:23:03 +0000102#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000103#ifdef BB_GREP
Matt Kraai27a80422000-07-19 19:24:01 +0000104 {"grep", grep_main, _BB_DIR_BIN, grep_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000105#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000106#ifdef BB_GUNZIP
Matt Kraai27a80422000-07-19 19:24:01 +0000107 {"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000108#endif
109#ifdef BB_GZIP
Matt Kraai27a80422000-07-19 19:24:01 +0000110 {"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000111#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000112#ifdef BB_HALT
Matt Kraai27a80422000-07-19 19:24:01 +0000113 {"halt", halt_main, _BB_DIR_SBIN, halt_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000114#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000115#ifdef BB_HEAD
Matt Kraai27a80422000-07-19 19:24:01 +0000116 {"head", head_main, _BB_DIR_USR_BIN, head_usage},
John Beppu3157b1f1999-12-10 07:42:50 +0000117#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000118#ifdef BB_HOSTID
Matt Kraai27a80422000-07-19 19:24:01 +0000119 {"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000120#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000121#ifdef BB_HOSTNAME
Matt Kraai27a80422000-07-19 19:24:01 +0000122 {"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
Eric Andersen485b9551999-12-07 23:14:59 +0000123#endif
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000124#ifdef BB_ID
Matt Kraai27a80422000-07-19 19:24:01 +0000125 {"id", id_main, _BB_DIR_USR_BIN, id_usage},
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000126#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000127#ifdef BB_INIT
Matt Kraai27a80422000-07-19 19:24:01 +0000128 {"init", init_main, _BB_DIR_SBIN, NULL},
Eric Andersencc8ed391999-10-05 16:24:54 +0000129#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000130#ifdef BB_INSMOD
Matt Kraai27a80422000-07-19 19:24:01 +0000131 {"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
Erik Andersen6da0ae81999-12-17 01:08:27 +0000132#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000133#ifdef BB_KILL
Matt Kraai27a80422000-07-19 19:24:01 +0000134 {"kill", kill_main, _BB_DIR_BIN, kill_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000135#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000136#ifdef BB_KILLALL
Matt Kraai27a80422000-07-19 19:24:01 +0000137 {"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
Erik Andersen246cc6d2000-03-07 07:41:42 +0000138#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000139#ifdef BB_LENGTH
Matt Kraai27a80422000-07-19 19:24:01 +0000140 {"length", length_main, _BB_DIR_USR_BIN, length_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000141#endif
Erik Andersen9a8195c2000-04-18 23:32:10 +0000142#ifdef BB_LINUXRC
Matt Kraai27a80422000-07-19 19:24:01 +0000143 {"linuxrc", init_main, _BB_DIR_ROOT, init_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000144#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000145#ifdef BB_LN
Matt Kraai27a80422000-07-19 19:24:01 +0000146 {"ln", ln_main, _BB_DIR_BIN, ln_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000147#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000148#ifdef BB_LOADACM
Matt Kraai27a80422000-07-19 19:24:01 +0000149 {"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000150#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000151#ifdef BB_LOADFONT
Matt Kraai27a80422000-07-19 19:24:01 +0000152 {"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000153#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000154#ifdef BB_LOADKMAP
Matt Kraai27a80422000-07-19 19:24:01 +0000155 {"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000156#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000157#ifdef BB_LOGGER
Matt Kraai27a80422000-07-19 19:24:01 +0000158 {"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000159#endif
160#ifdef BB_LOGNAME
Matt Kraai27a80422000-07-19 19:24:01 +0000161 {"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000162#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000163#ifdef BB_LS
Matt Kraai27a80422000-07-19 19:24:01 +0000164 {"ls", ls_main, _BB_DIR_BIN, ls_usage},
Erik Andersen6f23cec1999-12-15 22:14:12 +0000165#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000166#ifdef BB_LSMOD
Matt Kraai27a80422000-07-19 19:24:01 +0000167 {"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000168#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000169#ifdef BB_MAKEDEVS
Matt Kraai27a80422000-07-19 19:24:01 +0000170 {"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000171#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000172#ifdef BB_MD5SUM
Matt Kraai27a80422000-07-19 19:24:01 +0000173 {"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000174#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000175#ifdef BB_MKDIR
Matt Kraai27a80422000-07-19 19:24:01 +0000176 {"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
Erik Andersene49d5ec2000-02-08 19:58:47 +0000177#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000178#ifdef BB_MKFIFO
Matt Kraai27a80422000-07-19 19:24:01 +0000179 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
Eric Andersen19db07b1999-12-11 08:41:28 +0000180#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000181#ifdef BB_MKFS_MINIX
Matt Kraai27a80422000-07-19 19:24:01 +0000182 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000183#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000184#ifdef BB_MKNOD
Matt Kraai27a80422000-07-19 19:24:01 +0000185 {"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000186#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000187#ifdef BB_MKSWAP
Matt Kraai27a80422000-07-19 19:24:01 +0000188 {"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000189#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000190#ifdef BB_MKTEMP
Matt Kraai27a80422000-07-19 19:24:01 +0000191 {"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
Erik Andersen227a59b2000-04-25 23:24:55 +0000192#endif
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000193#ifdef BB_NC
Matt Kraai27a80422000-07-19 19:24:01 +0000194 {"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000195#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000196#ifdef BB_MORE
Matt Kraai27a80422000-07-19 19:24:01 +0000197 {"more", more_main, _BB_DIR_BIN, more_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000198#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000199#ifdef BB_MOUNT
Matt Kraai27a80422000-07-19 19:24:01 +0000200 {"mount", mount_main, _BB_DIR_BIN, mount_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000201#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000202#ifdef BB_MT
Matt Kraai27a80422000-07-19 19:24:01 +0000203 {"mt", mt_main, _BB_DIR_BIN, mt_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000204#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000205#ifdef BB_CP_MV
Matt Kraai27a80422000-07-19 19:24:01 +0000206 {"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000207#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000208#ifdef BB_NSLOOKUP
Matt Kraai27a80422000-07-19 19:24:01 +0000209 {"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
John Beppub332e772000-01-29 12:59:01 +0000210#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000211#ifdef BB_PING
Matt Kraai27a80422000-07-19 19:24:01 +0000212 {"ping", ping_main, _BB_DIR_BIN, ping_usage},
Eric Andersen485b9551999-12-07 23:14:59 +0000213#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000214#ifdef BB_POWEROFF
Matt Kraai27a80422000-07-19 19:24:01 +0000215 {"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
Eric Andersen2cb55071999-12-10 08:25:07 +0000216#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000217#ifdef BB_PRINTF
Matt Kraai27a80422000-07-19 19:24:01 +0000218 {"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000219#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000220#ifdef BB_PS
Matt Kraai27a80422000-07-19 19:24:01 +0000221 {"ps", ps_main, _BB_DIR_BIN, ps_usage},
Eric Andersenef8b6c71999-10-20 08:05:35 +0000222#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000223#ifdef BB_PWD
Matt Kraai27a80422000-07-19 19:24:01 +0000224 {"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000225#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000226#ifdef BB_REBOOT
Matt Kraai27a80422000-07-19 19:24:01 +0000227 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000228#endif
Eric Andersenbf960f52000-07-21 21:32:12 +0000229#ifdef BB_RENICE
230 {"renice", renice_main, _BB_DIR_USR_BIN},
231#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000232#ifdef BB_RM
Matt Kraai27a80422000-07-19 19:24:01 +0000233 {"rm", rm_main, _BB_DIR_BIN, rm_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000234#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000235#ifdef BB_RMDIR
Matt Kraai27a80422000-07-19 19:24:01 +0000236 {"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000237#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000238#ifdef BB_RMMOD
Matt Kraai27a80422000-07-19 19:24:01 +0000239 {"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
Erik Andersen3d7e3411999-12-16 23:04:20 +0000240#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000241#ifdef BB_SED
Matt Kraai27a80422000-07-19 19:24:01 +0000242 {"sed", sed_main, _BB_DIR_BIN, sed_usage},
Erik Andersen3522eb12000-03-12 23:49:18 +0000243#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000244#ifdef BB_SETKEYCODES
Matt Kraai27a80422000-07-19 19:24:01 +0000245 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
Erik Andersen3522eb12000-03-12 23:49:18 +0000246#endif
Erik Andersen4f3f7572000-04-28 00:18:56 +0000247#ifdef BB_SH
Matt Kraai27a80422000-07-19 19:24:01 +0000248 {"sh", shell_main, _BB_DIR_BIN, shell_usage},
Erik Andersen4f3f7572000-04-28 00:18:56 +0000249#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000250#ifdef BB_SLEEP
Matt Kraai27a80422000-07-19 19:24:01 +0000251 {"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000252#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000253#ifdef BB_SORT
Matt Kraai27a80422000-07-19 19:24:01 +0000254 {"sort", sort_main, _BB_DIR_BIN, sort_usage},
John Beppu019513a1999-12-22 17:57:31 +0000255#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000256#ifdef BB_SYNC
Matt Kraai27a80422000-07-19 19:24:01 +0000257 {"sync", sync_main, _BB_DIR_BIN, sync_usage},
Eric Andersen3843e961999-11-25 07:30:46 +0000258#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000259#ifdef BB_SYSLOGD
Matt Kraai27a80422000-07-19 19:24:01 +0000260 {"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
Eric Andersen3843e961999-11-25 07:30:46 +0000261#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000262#ifdef BB_SWAPONOFF
Matt Kraai27a80422000-07-19 19:24:01 +0000263 {"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000264#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000265#ifdef BB_SWAPONOFF
Matt Kraai27a80422000-07-19 19:24:01 +0000266 {"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000267#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000268#ifdef BB_TAIL
Matt Kraai27a80422000-07-19 19:24:01 +0000269 {"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000270#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000271#ifdef BB_TAR
Matt Kraai27a80422000-07-19 19:24:01 +0000272 {"tar", tar_main, _BB_DIR_BIN, tar_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000273#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000274#ifdef BB_TELNET
Matt Kraai27a80422000-07-19 19:24:01 +0000275 {"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000276#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000277#ifdef BB_TEST
Matt Kraai27a80422000-07-19 19:24:01 +0000278 {"test", test_main, _BB_DIR_USR_BIN, test_usage},
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000279#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000280#ifdef BB_TEE
Matt Kraai27a80422000-07-19 19:24:01 +0000281 {"tee", tee_main, _BB_DIR_BIN, tee_usage},
John Beppu059f1521999-12-10 05:27:16 +0000282#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000283#ifdef BB_TOUCH
Matt Kraai27a80422000-07-19 19:24:01 +0000284 {"touch", touch_main, _BB_DIR_USR_BIN, touch_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000285#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000286#ifdef BB_TR
Matt Kraai27a80422000-07-19 19:24:01 +0000287 {"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
Erik Andersenfb002d02000-03-05 08:07:00 +0000288#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000289#ifdef BB_TRUE_FALSE
Matt Kraai27a80422000-07-19 19:24:01 +0000290 {"true", true_main, _BB_DIR_BIN, true_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000291#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000292#ifdef BB_TTY
Matt Kraai27a80422000-07-19 19:24:01 +0000293 {"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
Erik Andersen05df2392000-01-13 04:43:48 +0000294#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000295#ifdef BB_UMOUNT
Matt Kraai27a80422000-07-19 19:24:01 +0000296 {"umount", umount_main, _BB_DIR_BIN, umount_usage},
Erik Andersen66be5e72000-03-05 07:52:05 +0000297#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000298#ifdef BB_UNAME
Matt Kraai27a80422000-07-19 19:24:01 +0000299 {"uname", uname_main, _BB_DIR_BIN, uname_usage},
Eric Andersen0460ff21999-10-25 23:32:44 +0000300#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000301#ifdef BB_UNIQ
Matt Kraai27a80422000-07-19 19:24:01 +0000302 {"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
John Beppuabb47722000-01-06 00:48:21 +0000303#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000304#ifdef BB_UPDATE
Matt Kraai27a80422000-07-19 19:24:01 +0000305 {"update", update_main, _BB_DIR_SBIN, update_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000306#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000307#ifdef BB_UPTIME
Matt Kraai27a80422000-07-19 19:24:01 +0000308 {"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
Erik Andersen5e1189e2000-04-15 16:34:54 +0000309#endif
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000310#ifdef BB_UUENCODE
Matt Kraai27a80422000-07-19 19:24:01 +0000311 {"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000312#endif
313#ifdef BB_UUDECODE
Matt Kraai27a80422000-07-19 19:24:01 +0000314 {"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000315#endif
Erik Andersenb99ca132000-04-04 18:49:18 +0000316#ifdef BB_USLEEP
Matt Kraai27a80422000-07-19 19:24:01 +0000317 {"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
Erik Andersenb99ca132000-04-04 18:49:18 +0000318#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000319#ifdef BB_WC
Matt Kraai27a80422000-07-19 19:24:01 +0000320 {"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000321#endif
Erik Andersen330fd2b2000-05-19 05:35:19 +0000322#ifdef BB_WHICH
Matt Kraai27a80422000-07-19 19:24:01 +0000323 {"which", which_main, _BB_DIR_USR_BIN, which_usage},
Erik Andersen330fd2b2000-05-19 05:35:19 +0000324#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000325#ifdef BB_WHOAMI
Matt Kraai27a80422000-07-19 19:24:01 +0000326 {"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000327#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000328#ifdef BB_YES
Matt Kraai27a80422000-07-19 19:24:01 +0000329 {"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
Erik Andersen31638212000-01-15 22:28:50 +0000330#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000331#ifdef BB_GUNZIP
Matt Kraai27a80422000-07-19 19:24:01 +0000332 {"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
Erik Andersend75af992000-03-16 08:09:09 +0000333#endif
Erik Andersen5e1189e2000-04-15 16:34:54 +0000334#ifdef BB_TEST
Matt Kraai27a80422000-07-19 19:24:01 +0000335 {"[", test_main, _BB_DIR_USR_BIN, test_usage},
Eric Andersencc8ed391999-10-05 16:24:54 +0000336#endif
Matt Kraai27a80422000-07-19 19:24:01 +0000337 {0,NULL,0,NULL}
Eric Andersencc8ed391999-10-05 16:24:54 +0000338};
339
Eric Andersen501c88b2000-07-28 15:14:45 +0000340const char *applet_name;
Erik Andersen05df2392000-01-13 04:43:48 +0000341
John Beppu8f425db2000-06-27 04:50:02 +0000342#ifdef BB_FEATURE_INSTALLER
343/*
344 * directory table
John Beppueb028332000-06-28 00:55:31 +0000345 * this should be consistent w/ the enum, internal.h::Location,
346 * or else...
John Beppu8f425db2000-06-27 04:50:02 +0000347 */
348static char* install_dir[] = {
John Beppueb028332000-06-28 00:55:31 +0000349 "/",
350 "/bin",
351 "/sbin",
352 "/usr/bin",
353 "/usr/sbin",
John Beppu8f425db2000-06-27 04:50:02 +0000354};
355
356/* abstract link() */
357typedef int (*__link_f)(const char *, const char *);
358
John Beppu7cdc76d2000-06-28 00:41:26 +0000359/*
360 * Where in the filesystem is this busybox?
361 * [return]
362 * malloc'd string w/ full pathname of busybox's location
363 * NULL on failure
364 */
365static char *busybox_fullpath()
366{
John Beppueb028332000-06-28 00:55:31 +0000367 pid_t pid;
368 char path[256];
369 char proc[256];
370 int len;
John Beppu7cdc76d2000-06-28 00:41:26 +0000371
372 pid = getpid();
373 sprintf(proc, "/proc/%d/exe", pid);
374 len = readlink(proc, path, 256);
375 if (len != -1) {
376 path[len] = 0;
377 } else {
Matt Kraaid537a952000-07-14 01:51:25 +0000378 errorMsg("%s: %s\n", proc, strerror(errno));
John Beppu7cdc76d2000-06-28 00:41:26 +0000379 return NULL;
380 }
381 return strdup(path);
382}
383
John Beppu8f425db2000-06-27 04:50:02 +0000384/* create (sym)links for each applet */
John Beppu495869f2000-06-27 07:54:33 +0000385static int install_links(const char *busybox, int use_symbolic_links)
John Beppu8f425db2000-06-27 04:50:02 +0000386{
John Beppueb028332000-06-28 00:55:31 +0000387 __link_f Link = link;
John Beppu8f425db2000-06-27 04:50:02 +0000388
John Beppueb028332000-06-28 00:55:31 +0000389 char command[256];
390 int i;
391 int rc = 0;
John Beppu8f425db2000-06-27 04:50:02 +0000392
393 if (use_symbolic_links) Link = symlink;
394
John Beppueb028332000-06-28 00:55:31 +0000395 for (i = 0; applets[i].name != NULL; i++) {
396 sprintf (
John Beppu8f425db2000-06-27 04:50:02 +0000397 command,
398 "%s/%s",
399 install_dir[applets[i].location],
400 applets[i].name
401 );
John Beppu7cdc76d2000-06-28 00:41:26 +0000402#if 1
John Beppueb028332000-06-28 00:55:31 +0000403 rc |= Link(busybox, command);
John Beppu8f425db2000-06-27 04:50:02 +0000404#else
John Beppueb028332000-06-28 00:55:31 +0000405 puts(command);
John Beppu8f425db2000-06-27 04:50:02 +0000406#endif
407 if (rc) {
Matt Kraaid537a952000-07-14 01:51:25 +0000408 errorMsg("%s: %s\n", command, strerror(errno));
John Beppu8f425db2000-06-27 04:50:02 +0000409 }
John Beppueb028332000-06-28 00:55:31 +0000410 }
John Beppu8f425db2000-06-27 04:50:02 +0000411 return rc;
412}
413
John Beppu8f425db2000-06-27 04:50:02 +0000414#endif /* BB_FEATURE_INSTALLER */
415
Erik Andersen05df2392000-01-13 04:43:48 +0000416
Eric Andersencc8ed391999-10-05 16:24:54 +0000417int main(int argc, char **argv)
418{
Eric Andersen501c88b2000-07-28 15:14:45 +0000419 const char *s;
Erik Andersenbcd61772000-05-13 06:33:19 +0000420 const struct BB_applet *a = applets;
Matt Kraaid537a952000-07-14 01:51:25 +0000421 applet_name = "busybox";
Eric Andersencc8ed391999-10-05 16:24:54 +0000422
John Beppu8f425db2000-06-27 04:50:02 +0000423#ifdef BB_FEATURE_INSTALLER
John Beppu27b59242000-06-27 04:56:45 +0000424 /*
425 * This style of argument parsing doesn't scale well
426 * in the event that busybox starts wanting more --options.
427 * If someone has a cleaner approach, by all means implement it.
428 */
John Beppu8f425db2000-06-27 04:50:02 +0000429 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
430 int use_symbolic_links = 0;
John Beppu7cdc76d2000-06-28 00:41:26 +0000431 int rc = 0;
432 char *busybox;
John Beppu8f425db2000-06-27 04:50:02 +0000433
John Beppu27b59242000-06-27 04:56:45 +0000434 /* to use symlinks, or not to use symlinks... */
John Beppu8f425db2000-06-27 04:50:02 +0000435 if (argc > 2) {
436 if ((strcmp(argv[2], "-s") == 0)) {
437 use_symbolic_links = 1;
438 }
439 }
John Beppu7cdc76d2000-06-28 00:41:26 +0000440
441 /* link */
442 busybox = busybox_fullpath();
443 if (busybox) {
444 install_links(busybox, use_symbolic_links);
445 free(busybox);
446 } else {
447 rc = 1;
448 }
449 return rc;
John Beppu8f425db2000-06-27 04:50:02 +0000450 }
451#endif /* BB_FEATURE_INSTALLER */
452
Matt Kraai77190082000-07-11 20:03:24 +0000453 for (s = applet_name = argv[0]; *s != '\0';) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000454 if (*s++ == '/')
Matt Kraai77190082000-07-11 20:03:24 +0000455 applet_name = s;
Eric Andersencc8ed391999-10-05 16:24:54 +0000456 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000457
Eric Andersen501c88b2000-07-28 15:14:45 +0000458 *argv = (char*)applet_name;
Erik Andersen029011b2000-03-04 21:19:32 +0000459
Eric Andersen5d41d602000-06-29 20:20:14 +0000460#ifdef BB_SH
461 /* Add in a special case hack -- whenever **argv == '-'
462 * (i.e. '-su' or '-sh') always invoke the shell */
Eric Andersenbf960f52000-07-21 21:32:12 +0000463 if (**argv == '-' && *(*argv+1)!= '-') {
Eric Andersen5d41d602000-06-29 20:20:14 +0000464 exit(((*(shell_main)) (argc, argv)));
Eric Andersenbf960f52000-07-21 21:32:12 +0000465 }
Eric Andersen5d41d602000-06-29 20:20:14 +0000466#endif
467
Erik Andersene49d5ec2000-02-08 19:58:47 +0000468 while (a->name != 0) {
Matt Kraai77190082000-07-11 20:03:24 +0000469 if (strcmp(applet_name, a->name) == 0) {
Matt Kraai27a80422000-07-19 19:24:01 +0000470 if (a->usage && argv[1] && strcmp(argv[1], "--help") == 0)
471 usage(a->usage);
Eric Andersenb6106152000-06-19 17:25:40 +0000472 exit(((*(a->main)) (argc, argv)));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000473 }
474 a++;
475 }
Eric Andersenb6106152000-06-19 17:25:40 +0000476 return(busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000477}
478
479
480int busybox_main(int argc, char **argv)
481{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000482 int col = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000483
Erik Andersene49d5ec2000-02-08 19:58:47 +0000484 argc--;
485 argv++;
Eric Andersencc8ed391999-10-05 16:24:54 +0000486
Erik Andersene49d5ec2000-02-08 19:58:47 +0000487 if (been_there_done_that == 1 || argc < 1) {
Erik Andersenbcd61772000-05-13 06:33:19 +0000488 const struct BB_applet *a = applets;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000489
Pavel Roskin9c5fcc32000-07-17 23:45:12 +0000490 fprintf(stderr, "%s\n\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000491 "Usage: busybox [function] [arguments]...\n"
492 " or: [function] [arguments]...\n\n"
John Beppub4f86062000-04-13 03:36:01 +0000493 "\tBusyBox is a multi-call binary that combines many common Unix\n"
494 "\tutilities into a single executable. Most people will create a\n"
495 "\tlink to busybox for each function they wish to use, and BusyBox\n"
Erik Andersen330fd2b2000-05-19 05:35:19 +0000496 "\twill act like whatever it was invoked as.\n"
Pavel Roskin9c5fcc32000-07-17 23:45:12 +0000497 "\nCurrently defined functions:\n", full_version);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000498
499 while (a->name != 0) {
500 col +=
501 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
502 (a++)->name);
503 if (col > 60 && a->name != 0) {
504 fprintf(stderr, ",\n");
505 col = 0;
506 }
507 }
508 fprintf(stderr, "\n\n");
509 exit(-1);
Eric Andersencc8ed391999-10-05 16:24:54 +0000510 }
Eric Andersenb6106152000-06-19 17:25:40 +0000511 /* If we've already been here once, exit now */
512 been_there_done_that = 1;
513 return (main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000514}
Erik Andersen029011b2000-03-04 21:19:32 +0000515
516/*
517Local Variables:
518c-file-style: "linux"
519c-basic-offset: 4
520tab-width: 4
521End:
522*/