blob: af81ad8a2996b15dd8a291a7ab352dedf9f6cd2c [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
30#ifdef BB_CP //bin
Eric Andersenf811e071999-10-09 00:25:00 +000031 {"cp", cp_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000032#endif
33#ifdef BB_DATE //bin
34 {"date", date_main},
35#endif
36#ifdef BB_DD //bin
37 {"dd", dd_main},
38#endif
39#ifdef BB_DF //bin
40 {"df", df_main},
41#endif
42#ifdef BB_DMESG //bin
43 {"dmesg", dmesg_main},
44#endif
45#ifdef BB_DUTMP //usr/sbin
Eric Andersene77ae3a1999-10-19 20:03:34 +000046 {"dutmp", dutmp_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000047#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000048#ifdef BB_FDFLUSH //bin
Eric Andersenf6be9441999-10-13 21:12:06 +000049 {"fdflush", fdflush_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000050#endif
51#ifdef BB_FIND //usr/bin
52 {"find", find_main},
53#endif
Eric Andersen0460ff21999-10-25 23:32:44 +000054#ifdef BB_CHVT //usr/bin
55 {"chvt", chvt_main},
56#endif
57#ifdef BB_DEALLOCVT //usr/bin
58 {"deallocvt", deallocvt_main},
59#endif
Eric Andersene494fdd1999-10-19 20:23:03 +000060#ifdef BB_FSCK_MINIX //sbin
61 {"fsck.minix", fsck_minix_main},
62#endif
63#ifdef BB_MKFS_MINIX //sbin
64 {"mkfs.minix", mkfs_minix_main},
65#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000066#ifdef BB_GREP //bin
67 {"grep", grep_main},
68#endif
69#ifdef BB_HALT //sbin
70 {"halt", halt_main},
71#endif
72#ifdef BB_INIT //sbin
73 {"init", init_main},
74#endif
Eric Andersen6a76e651999-11-19 05:31:45 +000075#ifdef BB_FEATURE_LINUXRC //
76 {"linuxrc", init_main},
77#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000078#ifdef BB_KILL //bin
79 {"kill", kill_main},
80#endif
81#ifdef BB_LENGTH //usr/bin
82 {"length", length_main},
83#endif
84#ifdef BB_LN //bin
Eric Andersenf6be9441999-10-13 21:12:06 +000085 {"ln", ln_main},
Eric Andersencc8ed391999-10-05 16:24:54 +000086#endif
Eric Andersen3e0fbae1999-10-19 06:02:44 +000087#ifdef BB_LOADFONT //usr/bin
88 {"loadfont", loadfont_main},
89#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000090#ifdef BB_LOADKMAP //sbin
91 {"loadkmap", loadkmap_main},
92#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000093#ifdef BB_LS //bin
94 {"ls", ls_main},
95#endif
96#ifdef BB_MAKEDEVS //sbin
97 {"makedevs", makedevs_main},
98#endif
99#ifdef BB_MATH //usr/bin
100 {"math", math_main},
101#endif
102#ifdef BB_MKDIR //bin
Eric Andersenf6be9441999-10-13 21:12:06 +0000103 {"mkdir", mkdir_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000104#endif
105#ifdef BB_MKNOD //bin
106 {"mknod", mknod_main},
107#endif
108#ifdef BB_MKSWAP //sbin
109 {"mkswap", mkswap_main},
110#endif
111#ifdef BB_MNC //usr/bin
112 {"mnc", mnc_main},
113#endif
114#ifdef BB_MORE //bin
Eric Andersen4bea32a1999-10-06 00:30:51 +0000115 {"more", more_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000116#endif
117#ifdef BB_MOUNT //bin
118 {"mount", mount_main},
119#endif
120#ifdef BB_MT //bin
121 {"mt", mt_main},
122#endif
123#ifdef BB_MV //bin
Eric Andersen596e5461999-10-07 08:30:23 +0000124 {"mv", mv_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000125#endif
126#ifdef BB_PRINTF //usr/bin
127 {"printf", printf_main},
128#endif
Eric Andersenef8b6c71999-10-20 08:05:35 +0000129#ifdef BB_PS //bin
130 {"ps", ps_main},
131#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000132#ifdef BB_PWD //bin
133 {"pwd", pwd_main},
134#endif
135#ifdef BB_REBOOT //sbin
136 {"reboot", reboot_main},
137#endif
138#ifdef BB_RM //bin
139 {"rm", rm_main},
140#endif
141#ifdef BB_RMDIR //bin
Eric Andersenf6be9441999-10-13 21:12:06 +0000142 {"rmdir", rmdir_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000143#endif
Eric Andersene77ae3a1999-10-19 20:03:34 +0000144#ifdef BB_SFDISK //sbin
145 {"fdisk", sfdisk_main},
146 {"sfdisk", sfdisk_main},
147#endif
Eric Andersenc1525e81999-10-29 00:07:31 +0000148#ifdef BB_SED //bin
149 {"sed", sed_main},
150#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000151#ifdef BB_SLEEP //bin
152 {"sleep", sleep_main},
153#endif
Eric Andersen3843e961999-11-25 07:30:46 +0000154#ifdef BB_SYNC //bin
155 {"sync", sync_main},
156#endif
157#ifdef BB_SYSLOGD //sbin
158 {"syslogd", syslogd_main},
159#endif
160#ifdef BB_LOGGER //usr/bin
161 {"logger", logger_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000162#endif
Eric Andersen87590061999-10-18 21:22:59 +0000163#ifdef BB_SWAPONOFF //sbin
164 {"swapon", swap_on_off_main},
165 {"swapoff", swap_on_off_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000166#endif
Eric Andersen3843e961999-11-25 07:30:46 +0000167#ifdef BB_TAR //bin
168 {"tar", tar_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000169#endif
170#ifdef BB_TOUCH //usr/bin
Eric Andersen596e5461999-10-07 08:30:23 +0000171 {"touch", touch_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000172#endif
Eric Andersena3f09071999-10-19 16:39:10 +0000173#ifdef BB_TRUE_FALSE //bin
Eric Andersencc8ed391999-10-05 16:24:54 +0000174 {"true", true_main},
Eric Andersena3f09071999-10-19 16:39:10 +0000175 {"false", false_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000176#endif
Eric Andersen0460ff21999-10-25 23:32:44 +0000177#ifdef BB_UNAME //bin
178 {"uname", uname_main},
179#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000180#ifdef BB_UMOUNT //bin
Eric Andersen87590061999-10-18 21:22:59 +0000181 {"umount", umount_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000182#endif
183#ifdef BB_UPDATE //sbin
184 {"update", update_main},
185#endif
Eric Andersend80e8511999-11-16 00:46:00 +0000186#ifdef BB_GUNZIP //bin
187 {"zcat", gunzip_main},
188 {"gunzip", gunzip_main},
Eric Andersencc8ed391999-10-05 16:24:54 +0000189#endif
190#ifdef BB_GZIP //bin
191 {"gzip", gzip_main},
192#endif
193 {0}
194};
195
196int main(int argc, char **argv)
197{
198 char *s = argv[0];
199 char *name = argv[0];
200 const struct Applet *a = applets;
201
202 while (*s != '\0') {
203 if (*s++ == '/')
204 name = s;
205 }
206
207 while (a->name != 0) {
208 if (strcmp(name, a->name) == 0) {
209 int status;
210
211 status = ((*(a->main)) (argc, argv));
212 if (status < 0) {
213 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
214 }
215 fprintf(stderr, "\n");
216 exit(status);
217 }
218 a++;
219 }
Eric Andersen2ce1edc1999-10-12 15:42:48 +0000220 exit (busybox_main(argc, argv));
Eric Andersencc8ed391999-10-05 16:24:54 +0000221}
222
223
224int busybox_main(int argc, char **argv)
225{
Eric Andersen17d49ef1999-10-06 20:25:32 +0000226 int col=0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000227 argc--;
228 argv++;
229
Eric Andersenc6cb79d1999-10-13 18:01:10 +0000230 if (been_there_done_that == 1 || argc < 1) {
Eric Andersencc8ed391999-10-05 16:24:54 +0000231 const struct Applet *a = applets;
Eric Andersend73dc5b1999-11-10 23:13:02 +0000232 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
Eric Andersencc8ed391999-10-05 16:24:54 +0000233 BB_VER, BB_BT);
Eric Andersend73dc5b1999-11-10 23:13:02 +0000234 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
235 fprintf(stderr, " or: [function] [arguments]...\n\n");
Eric Andersencc8ed391999-10-05 16:24:54 +0000236 fprintf(stderr,
Eric Andersend73dc5b1999-11-10 23:13:02 +0000237 "\tMost people will create a symlink to busybox for each\n"
Eric Andersencc8ed391999-10-05 16:24:54 +0000238 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
239 fprintf(stderr, "\nCurrently defined functions:\n");
240
Eric Andersencc8ed391999-10-05 16:24:54 +0000241 while (a->name != 0) {
Eric Andersen2ce1edc1999-10-12 15:42:48 +0000242 col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
Eric Andersen17d49ef1999-10-06 20:25:32 +0000243 if (col>60) {
244 fprintf(stderr, ",\n");
245 col=0;
246 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000247 }
248 fprintf(stderr, "\n\n");
249 exit(-1);
Eric Andersenc6cb79d1999-10-13 18:01:10 +0000250 } else {
251 /* If we've already been here once, exit now */
252 been_there_done_that = 1;
Eric Andersencc8ed391999-10-05 16:24:54 +0000253 return (main(argc, argv));
Eric Andersenc6cb79d1999-10-13 18:01:10 +0000254 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000255}