blob: a9cd6e07902c0cdba4eab0eee170e5bfa49c989b [file] [log] [blame]
Eric Andersencc8ed391999-10-05 16:24:54 +00001#include "internal.h"
2#include <stdio.h>
3#include <string.h>
4#include <errno.h>
5
6static int been_there_done_that = 0;
7
8static const struct Applet applets[] = {
9
10#ifdef BB_BUSYBOX //bin
11 {"busybox", busybox_main},
12#endif
13#ifdef BB_BLOCK_DEVICE //sbin
14 {"block_device", block_device_main},
15#endif
16#ifdef BB_CAT //bin
Eric Andersene77ae3a1999-10-19 20:03:34 +000017 {"cat", cat_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000018#endif
Eric Andersen1b61f411999-10-13 18:56:42 +000019#ifdef BB_CHMOD_CHOWN_CHGRP //bin
20 {"chmod", chmod_chown_chgrp_main},
21 {"chown", chmod_chown_chgrp_main},
22 {"chgrp", chmod_chown_chgrp_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000023#endif
24#ifdef BB_CHROOT //sbin
25 {"chroot", chroot_main},
26#endif
27#ifdef BB_CLEAR //usr/bin
28 {"clear", clear_main},
29#endif
Eric Andersenabc0f4f1999-12-08 23:19:36 +000030#ifdef BB_CHVT //usr/bin
31 {"chvt", chvt_main},
32#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000033#ifdef BB_CP //bin
Eric Andersenf811e071999-10-09 00:25:00 +000034 {"cp", cp_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000035#endif
36#ifdef BB_DATE //bin
37 {"date", date_main},
38#endif
39#ifdef BB_DD //bin
40 {"dd", dd_main},
41#endif
42#ifdef BB_DF //bin
43 {"df", df_main},
44#endif
45#ifdef BB_DMESG //bin
46 {"dmesg", dmesg_main},
47#endif
John Beppu7a986061999-12-09 18:29:29 +000048#ifdef BB_DU //bin
49 {"du", du_main},
50#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000051#ifdef BB_DUTMP //usr/sbin
Eric Andersene77ae3a1999-10-19 20:03:34 +000052 {"dutmp", dutmp_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000053#endif
Erik Andersen1c5b2581999-12-16 20:59:36 +000054#ifdef BB_FBSET //usr/sbin
55 {"fbset", fbset_main},
56#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000057#ifdef BB_FDFLUSH //bin
Eric Andersenf6be9441999-10-13 21:12:06 +000058 {"fdflush", fdflush_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000059#endif
60#ifdef BB_FIND //usr/bin
61 {"find", find_main},
62#endif
Eric Andersenabc0f4f1999-12-08 23:19:36 +000063#ifdef BB_FREE //usr/bin
64 {"free", free_main},
Eric Andersen0460ff21999-10-25 23:32:44 +000065#endif
66#ifdef BB_DEALLOCVT //usr/bin
67 {"deallocvt", deallocvt_main},
68#endif
Eric Andersene494fdd1999-10-19 20:23:03 +000069#ifdef BB_FSCK_MINIX //sbin
70 {"fsck.minix", fsck_minix_main},
71#endif
72#ifdef BB_MKFS_MINIX //sbin
73 {"mkfs.minix", mkfs_minix_main},
74#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000075#ifdef BB_GREP //bin
76 {"grep", grep_main},
77#endif
78#ifdef BB_HALT //sbin
79 {"halt", halt_main},
80#endif
John Beppu3157b1f1999-12-10 07:42:50 +000081#ifdef BB_HEAD //bin
82 {"head", head_main},
83#endif
Eric Andersen485b9551999-12-07 23:14:59 +000084#ifdef BB_HOSTNAME //bin
85 {"hostname", hostname_main},
86#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000087#ifdef BB_INIT //sbin
88 {"init", init_main},
89#endif
Eric Andersen6a76e651999-11-19 05:31:45 +000090#ifdef BB_FEATURE_LINUXRC //
91 {"linuxrc", init_main},
92#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000093#ifdef BB_KILL //bin
94 {"kill", kill_main},
95#endif
96#ifdef BB_LENGTH //usr/bin
97 {"length", length_main},
98#endif
99#ifdef BB_LN //bin
Eric Andersenf6be9441999-10-13 21:12:06 +0000100 {"ln", ln_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000101#endif
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000102#ifdef BB_LOADFONT //usr/bin
103 {"loadfont", loadfont_main},
104#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000105#ifdef BB_LOADKMAP //sbin
106 {"loadkmap", loadkmap_main},
107#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000108#ifdef BB_LS //bin
109 {"ls", ls_main},
110#endif
Erik Andersen6f23cec1999-12-15 22:14:12 +0000111#ifdef BB_LSMOD //sbin
112 {"lsmod", lsmod_main},
113#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000114#ifdef BB_MAKEDEVS //sbin
115 {"makedevs", makedevs_main},
116#endif
117#ifdef BB_MATH //usr/bin
118 {"math", math_main},
119#endif
120#ifdef BB_MKDIR //bin
Eric Andersenf6be9441999-10-13 21:12:06 +0000121 {"mkdir", mkdir_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000122#endif
Eric Andersen19db07b1999-12-11 08:41:28 +0000123#ifdef BB_MKFIFO //usr/bin
124 {"mkfifo", mkfifo_main},
125#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000126#ifdef BB_MKNOD //bin
127 {"mknod", mknod_main},
128#endif
129#ifdef BB_MKSWAP //sbin
130 {"mkswap", mkswap_main},
131#endif
132#ifdef BB_MNC //usr/bin
133 {"mnc", mnc_main},
134#endif
135#ifdef BB_MORE //bin
Eric Andersen4bea32a1999-10-06 00:30:51 +0000136 {"more", more_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000137#endif
138#ifdef BB_MOUNT //bin
139 {"mount", mount_main},
140#endif
141#ifdef BB_MT //bin
142 {"mt", mt_main},
143#endif
144#ifdef BB_MV //bin
Eric Andersen596e5461999-10-07 08:30:23 +0000145 {"mv", mv_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000146#endif
Eric Andersen485b9551999-12-07 23:14:59 +0000147#ifdef BB_PING //bin
148 {"ping", ping_main},
149#endif
Eric Andersen2cb55071999-12-10 08:25:07 +0000150#ifdef BB_POWEROFF //sbin
151 {"poweroff", poweroff_main},
152#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000153#ifdef BB_PRINTF //usr/bin
154 {"printf", printf_main},
155#endif
Eric Andersenef8b6c71999-10-20 08:05:35 +0000156#ifdef BB_PS //bin
157 {"ps", ps_main},
158#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000159#ifdef BB_PWD //bin
160 {"pwd", pwd_main},
161#endif
162#ifdef BB_REBOOT //sbin
163 {"reboot", reboot_main},
164#endif
165#ifdef BB_RM //bin
166 {"rm", rm_main},
167#endif
168#ifdef BB_RMDIR //bin
Eric Andersenf6be9441999-10-13 21:12:06 +0000169 {"rmdir", rmdir_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000170#endif
Erik Andersen3d7e3411999-12-16 23:04:20 +0000171#ifdef BB_RMMOD //sbin
172 {"rmmod", rmmod_main},
173#endif
Eric Andersene77ae3a1999-10-19 20:03:34 +0000174#ifdef BB_SFDISK //sbin
175 {"fdisk", sfdisk_main},
176 {"sfdisk", sfdisk_main},
177#endif
Eric Andersenc1525e81999-10-29 00:07:31 +0000178#ifdef BB_SED //bin
179 {"sed", sed_main},
180#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000181#ifdef BB_SLEEP //bin
182 {"sleep", sleep_main},
183#endif
Eric Andersen3843e961999-11-25 07:30:46 +0000184#ifdef BB_SYNC //bin
185 {"sync", sync_main},
186#endif
187#ifdef BB_SYSLOGD //sbin
188 {"syslogd", syslogd_main},
189#endif
190#ifdef BB_LOGGER //usr/bin
191 {"logger", logger_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000192#endif
Eric Andersen87590061999-10-18 21:22:59 +0000193#ifdef BB_SWAPONOFF //sbin
194 {"swapon", swap_on_off_main},
195 {"swapoff", swap_on_off_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000196#endif
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000197#ifdef BB_TAIL //usr/bin
198 {"tail", tail_main},
199#endif
Eric Andersen3843e961999-11-25 07:30:46 +0000200#ifdef BB_TAR //bin
201 {"tar", tar_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000202#endif
John Beppu059f1521999-12-10 05:27:16 +0000203#ifdef BB_TEE //bin
204 {"tee", tee_main},
205#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000206#ifdef BB_TOUCH //usr/bin
Eric Andersen596e5461999-10-07 08:30:23 +0000207 {"touch", touch_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000208#endif
Eric Andersena3f09071999-10-19 16:39:10 +0000209#ifdef BB_TRUE_FALSE //bin
Eric Andersencc8ed391999-10-05 16:24:54 +0000210 {"true", true_main},
Eric Andersena3f09071999-10-19 16:39:10 +0000211 {"false", false_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000212#endif
Eric Andersen0460ff21999-10-25 23:32:44 +0000213#ifdef BB_UNAME //bin
214 {"uname", uname_main},
215#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000216#ifdef BB_UMOUNT //bin
Eric Andersen87590061999-10-18 21:22:59 +0000217 {"umount", umount_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000218#endif
219#ifdef BB_UPDATE //sbin
220 {"update", update_main},
221#endif
Eric Andersend80e8511999-11-16 00:46:00 +0000222#ifdef BB_GUNZIP //bin
223 {"zcat", gunzip_main},
224 {"gunzip", gunzip_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000225#endif
226#ifdef BB_GZIP //bin
227 {"gzip", gzip_main},
228#endif
229 {0}
230};
231
232int main(int argc, char **argv)
233{
234 char *s = argv[0];
235 char *name = argv[0];
236 const struct Applet *a = applets;
237
238 while (*s != '\0') {
239 if (*s++ == '/')
240 name = s;
241 }
242
243 while (a->name != 0) {
244 if (strcmp(name, a->name) == 0) {
245 int status;
246
247 status = ((*(a->main)) (argc, argv));
248 if (status < 0) {
249 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
250 }
251 fprintf(stderr, "\n");
252 exit(status);
253 }
254 a++;
255 }
Eric Andersen2ce1edc1999-10-12 15:42:48 +0000256 exit (busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000257}
258
259
260int busybox_main(int argc, char **argv)
261{
Eric Andersen17d49ef1999-10-06 20:25:32 +0000262 int col=0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000263 argc--;
264 argv++;
265
Eric Andersenc6cb79d1999-10-13 18:01:10 +0000266 if (been_there_done_that == 1 || argc < 1) {
Eric Andersencc8ed391999-10-05 16:24:54 +0000267 const struct Applet *a = applets;
Eric Andersend73dc5b1999-11-10 23:13:02 +0000268 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
Eric Andersencc8ed391999-10-05 16:24:54 +0000269 BB_VER, BB_BT);
Eric Andersend73dc5b1999-11-10 23:13:02 +0000270 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
271 fprintf(stderr, " or: [function] [arguments]...\n\n");
Eric Andersencc8ed391999-10-05 16:24:54 +0000272 fprintf(stderr,
Eric Andersend73dc5b1999-11-10 23:13:02 +0000273 "\tMost people will create a symlink to busybox for each\n"
Eric Andersencc8ed391999-10-05 16:24:54 +0000274 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
275 fprintf(stderr, "\nCurrently defined functions:\n");
276
Eric Andersencc8ed391999-10-05 16:24:54 +0000277 while (a->name != 0) {
Eric Andersen2ce1edc1999-10-12 15:42:48 +0000278 col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
Eric Andersen17d49ef1999-10-06 20:25:32 +0000279 if (col>60) {
280 fprintf(stderr, ",\n");
281 col=0;
282 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000283 }
284 fprintf(stderr, "\n\n");
285 exit(-1);
Eric Andersenc6cb79d1999-10-13 18:01:10 +0000286 } else {
287 /* If we've already been here once, exit now */
288 been_there_done_that = 1;
Eric Andersencc8ed391999-10-05 16:24:54 +0000289 return (main(argc, argv));
Eric Andersenc6cb79d1999-10-13 18:01:10 +0000290 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000291}