aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
Diffstat (limited to 'applets')
-rw-r--r--applets/busybox.c456
1 files changed, 235 insertions, 221 deletions
diff --git a/applets/busybox.c b/applets/busybox.c
index e2c2e0393..8bbe6a22e 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1#include "internal.h" 2#include "internal.h"
2#include <stdio.h> 3#include <stdio.h>
3#include <string.h> 4#include <string.h>
@@ -16,329 +17,342 @@ static int been_there_done_that = 0;
16 * replacement may be in order 17 * replacement may be in order
17 */ 18 */
18#if 0 19#if 0
19void exit (int status) __attribute__ ((noreturn)); 20void exit(int status) __attribute__ ((noreturn));
20void exit (int status) { _exit(status); }; 21void exit(int status)
21void abort (void) __attribute__ ((__noreturn__)); 22{
22void abort (void) { _exit(0); }; 23 _exit(status);
23int atexit (void (*__func) (void)) { _exit(0); }; 24};
25void abort(void) __attribute__ ((__noreturn__));
26void abort(void)
27{
28 _exit(0);
29};
30int atexit(void (*__func) (void))
31{
32 _exit(0);
33};
24void *__libc_stack_end; 34void *__libc_stack_end;
25#endif 35#endif
26 36
27 37
28static const struct Applet applets[] = { 38static const struct Applet applets[] = {
29 39
30#ifdef BB_BUSYBOX //bin 40#ifdef BB_BUSYBOX //bin
31 {"busybox", busybox_main}, 41 {"busybox", busybox_main},
42#endif
43#ifdef BB_BLOCK_DEVICE //sbin
44 {"block_device", block_device_main},
32#endif 45#endif
33#ifdef BB_BLOCK_DEVICE //sbin 46#ifdef BB_CAT //bin
34 {"block_device", block_device_main}, 47 {"cat", cat_main},
35#endif 48#endif
36#ifdef BB_CAT //bin 49#ifdef BB_CHMOD_CHOWN_CHGRP //bin
37 {"cat", cat_main}, 50 {"chmod", chmod_chown_chgrp_main},
51 {"chown", chmod_chown_chgrp_main},
52 {"chgrp", chmod_chown_chgrp_main},
38#endif 53#endif
39#ifdef BB_CHMOD_CHOWN_CHGRP //bin 54#ifdef BB_CHROOT //sbin
40 {"chmod", chmod_chown_chgrp_main}, 55 {"chroot", chroot_main},
41 {"chown", chmod_chown_chgrp_main},
42 {"chgrp", chmod_chown_chgrp_main},
43#endif 56#endif
44#ifdef BB_CHROOT //sbin 57#ifdef BB_CLEAR //usr/bin
45 {"chroot", chroot_main}, 58 {"clear", clear_main},
46#endif 59#endif
47#ifdef BB_CLEAR //usr/bin 60#ifdef BB_CHVT //usr/bin
48 {"clear", clear_main}, 61 {"chvt", chvt_main},
49#endif 62#endif
50#ifdef BB_CHVT //usr/bin 63#ifdef BB_CP_MV //bin
51 {"chvt", chvt_main}, 64 {"cp", cp_mv_main},
65 {"mv", cp_mv_main},
52#endif 66#endif
53#ifdef BB_CP_MV //bin 67#ifdef BB_DATE //bin
54 {"cp", cp_mv_main}, 68 {"date", date_main},
55 {"mv", cp_mv_main},
56#endif 69#endif
57#ifdef BB_DATE //bin 70#ifdef BB_DD //bin
58 {"date", date_main}, 71 {"dd", dd_main},
59#endif 72#endif
60#ifdef BB_DD //bin 73#ifdef BB_DF //bin
61 {"dd", dd_main}, 74 {"df", df_main},
62#endif 75#endif
63#ifdef BB_DF //bin 76#ifdef BB_DMESG //bin
64 {"df", df_main}, 77 {"dmesg", dmesg_main},
65#endif 78#endif
66#ifdef BB_DMESG //bin 79#ifdef BB_DU //bin
67 {"dmesg", dmesg_main}, 80 {"du", du_main},
68#endif 81#endif
69#ifdef BB_DU //bin 82#ifdef BB_DUTMP //usr/sbin
70 {"du", du_main}, 83 {"dutmp", dutmp_main},
71#endif 84#endif
72#ifdef BB_DUTMP //usr/sbin 85#ifdef BB_FBSET //usr/sbin
73 {"dutmp", dutmp_main}, 86 {"fbset", fbset_main},
74#endif 87#endif
75#ifdef BB_FBSET //usr/sbin 88#ifdef BB_FDFLUSH //bin
76 {"fbset", fbset_main}, 89 {"fdflush", fdflush_main},
77#endif 90#endif
78#ifdef BB_FDFLUSH //bin 91#ifdef BB_FIND //usr/bin
79 {"fdflush", fdflush_main}, 92 {"find", find_main},
80#endif 93#endif
81#ifdef BB_FIND //usr/bin 94#ifdef BB_FREE //usr/bin
82 {"find", find_main}, 95 {"free", free_main},
83#endif 96#endif
84#ifdef BB_FREE //usr/bin 97#ifdef BB_DEALLOCVT //usr/bin
85 {"free", free_main}, 98 {"deallocvt", deallocvt_main},
86#endif 99#endif
87#ifdef BB_DEALLOCVT //usr/bin 100#ifdef BB_FSCK_MINIX //sbin
88 {"deallocvt", deallocvt_main}, 101 {"fsck.minix", fsck_minix_main},
89#endif 102#endif
90#ifdef BB_FSCK_MINIX //sbin 103#ifdef BB_MKFS_MINIX //sbin
91 {"fsck.minix", fsck_minix_main}, 104 {"mkfs.minix", mkfs_minix_main},
92#endif 105#endif
93#ifdef BB_MKFS_MINIX //sbin 106#ifdef BB_GREP //bin
94 {"mkfs.minix", mkfs_minix_main}, 107 {"grep", grep_main},
95#endif 108#endif
96#ifdef BB_GREP //bin 109#ifdef BB_HALT //sbin
97 {"grep", grep_main}, 110 {"halt", halt_main},
98#endif 111#endif
99#ifdef BB_HALT //sbin 112#ifdef BB_HEAD //bin
100 {"halt", halt_main}, 113 {"head", head_main},
101#endif 114#endif
102#ifdef BB_HEAD //bin 115#ifdef BB_HOSTID //usr/bin
103 {"head", head_main}, 116 {"hostid", hostid_main},
104#endif 117#endif
105#ifdef BB_HOSTID //usr/bin 118#ifdef BB_HOSTNAME //bin
106 {"hostid", hostid_main}, 119 {"hostname", hostname_main},
107#endif 120#endif
108#ifdef BB_HOSTNAME //bin 121#ifdef BB_INIT //sbin
109 {"hostname", hostname_main}, 122 {"init", init_main},
110#endif 123#endif
111#ifdef BB_INIT //sbin 124#ifdef BB_INSMOD //sbin
112 {"init", init_main}, 125 {"insmod", insmod_main},
113#endif 126#endif
114#ifdef BB_INSMOD //sbin 127#ifdef BB_FEATURE_LINUXRC //
115 {"insmod", insmod_main}, 128 {"linuxrc", init_main},
116#endif 129#endif
117#ifdef BB_FEATURE_LINUXRC // 130#ifdef BB_KILL //bin
118 {"linuxrc", init_main}, 131 {"kill", kill_main},
119#endif 132#endif
120#ifdef BB_KILL //bin 133#ifdef BB_LENGTH //usr/bin
121 {"kill", kill_main}, 134 {"length", length_main},
122#endif 135#endif
123#ifdef BB_LENGTH //usr/bin 136#ifdef BB_LN //bin
124 {"length", length_main}, 137 {"ln", ln_main},
125#endif 138#endif
126#ifdef BB_LN //bin 139#ifdef BB_LOADACM //usr/bin
127 {"ln", ln_main}, 140 {"loadacm", loadacm_main},
128#endif 141#endif
129#ifdef BB_LOADACM //usr/bin 142#ifdef BB_LOADFONT //usr/bin
130 {"loadacm", loadacm_main}, 143 {"loadfont", loadfont_main},
131#endif
132#ifdef BB_LOADFONT //usr/bin
133 {"loadfont", loadfont_main},
134#endif 144#endif
135#ifdef BB_LOADKMAP //sbin 145#ifdef BB_LOADKMAP //sbin
136 {"loadkmap", loadkmap_main}, 146 {"loadkmap", loadkmap_main},
137#endif 147#endif
138#ifdef BB_LS //bin 148#ifdef BB_LS //bin
139 {"ls", ls_main}, 149 {"ls", ls_main},
140#endif 150#endif
141#ifdef BB_LSMOD //sbin 151#ifdef BB_LSMOD //sbin
142 {"lsmod", lsmod_main}, 152 {"lsmod", lsmod_main},
143#endif 153#endif
144#ifdef BB_MAKEDEVS //sbin 154#ifdef BB_MAKEDEVS //sbin
145 {"makedevs", makedevs_main}, 155 {"makedevs", makedevs_main},
146#endif 156#endif
147#ifdef BB_MATH //usr/bin 157#ifdef BB_MATH //usr/bin
148 {"math", math_main}, 158 {"math", math_main},
149#endif 159#endif
150#ifdef BB_MKDIR //bin 160#ifdef BB_MKDIR //bin
151 {"mkdir", mkdir_main}, 161 {"mkdir", mkdir_main},
152#endif 162#endif
153#ifdef BB_MKFIFO //usr/bin 163#ifdef BB_MKFIFO //usr/bin
154 {"mkfifo", mkfifo_main}, 164 {"mkfifo", mkfifo_main},
155#endif 165#endif
156#ifdef BB_MKNOD //bin 166#ifdef BB_MKNOD //bin
157 {"mknod", mknod_main}, 167 {"mknod", mknod_main},
158#endif 168#endif
159#ifdef BB_MKSWAP //sbin 169#ifdef BB_MKSWAP //sbin
160 {"mkswap", mkswap_main}, 170 {"mkswap", mkswap_main},
161#endif 171#endif
162#ifdef BB_MNC //usr/bin 172#ifdef BB_MNC //usr/bin
163 {"mnc", mnc_main}, 173 {"mnc", mnc_main},
164#endif 174#endif
165#ifdef BB_MORE //bin 175#ifdef BB_MORE //bin
166 {"more", more_main}, 176 {"more", more_main},
167#endif 177#endif
168#ifdef BB_MOUNT //bin 178#ifdef BB_MOUNT //bin
169 {"mount", mount_main}, 179 {"mount", mount_main},
170#endif 180#endif
171#ifdef BB_MT //bin 181#ifdef BB_MT //bin
172 {"mt", mt_main}, 182 {"mt", mt_main},
173#endif 183#endif
174#ifdef BB_NSLOOKUP //usr/bin 184#ifdef BB_NSLOOKUP //usr/bin
175 {"nslookup", nslookup_main}, 185 {"nslookup", nslookup_main},
176#endif 186#endif
177#ifdef BB_PING //bin 187#ifdef BB_PING //bin
178 {"ping", ping_main}, 188 {"ping", ping_main},
179#endif 189#endif
180#ifdef BB_POWEROFF //sbin 190#ifdef BB_POWEROFF //sbin
181 {"poweroff", poweroff_main}, 191 {"poweroff", poweroff_main},
182#endif 192#endif
183#ifdef BB_PRINTF //usr/bin 193#ifdef BB_PRINTF //usr/bin
184 {"printf", printf_main}, 194 {"printf", printf_main},
185#endif 195#endif
186#ifdef BB_PS //bin 196#ifdef BB_PS //bin
187 {"ps", ps_main}, 197 {"ps", ps_main},
188#endif 198#endif
189#ifdef BB_PWD //bin 199#ifdef BB_PWD //bin
190 {"pwd", pwd_main}, 200 {"pwd", pwd_main},
191#endif 201#endif
192#ifdef BB_REBOOT //sbin 202#ifdef BB_REBOOT //sbin
193 {"reboot", reboot_main}, 203 {"reboot", reboot_main},
194#endif 204#endif
195#ifdef BB_RM //bin 205#ifdef BB_RM //bin
196 {"rm", rm_main}, 206 {"rm", rm_main},
197#endif 207#endif
198#ifdef BB_RMDIR //bin 208#ifdef BB_RMDIR //bin
199 {"rmdir", rmdir_main}, 209 {"rmdir", rmdir_main},
200#endif 210#endif
201#ifdef BB_RMMOD //sbin 211#ifdef BB_RMMOD //sbin
202 {"rmmod", rmmod_main}, 212 {"rmmod", rmmod_main},
203#endif 213#endif
204#ifdef BB_SFDISK //sbin 214#ifdef BB_SFDISK //sbin
205 {"fdisk", sfdisk_main}, 215 {"fdisk", sfdisk_main},
206 {"sfdisk", sfdisk_main}, 216 {"sfdisk", sfdisk_main},
207#endif 217#endif
208#ifdef BB_SED //bin 218#ifdef BB_SED //bin
209 {"sed", sed_main}, 219 {"sed", sed_main},
210#endif 220#endif
211#ifdef BB_SLEEP //bin 221#ifdef BB_SLEEP //bin
212 {"sleep", sleep_main}, 222 {"sleep", sleep_main},
213#endif 223#endif
214#ifdef BB_SORT //bin 224#ifdef BB_SORT //bin
215 {"sort", sort_main}, 225 {"sort", sort_main},
216#endif 226#endif
217#ifdef BB_SYNC //bin 227#ifdef BB_SYNC //bin
218 {"sync", sync_main}, 228 {"sync", sync_main},
219#endif 229#endif
220#ifdef BB_SYSLOGD //sbin 230#ifdef BB_SYSLOGD //sbin
221 {"syslogd", syslogd_main}, 231 {"syslogd", syslogd_main},
222#endif 232#endif
223#ifdef BB_LOGGER //usr/bin 233#ifdef BB_LOGGER //usr/bin
224 {"logger", logger_main}, 234 {"logger", logger_main},
225#endif 235#endif
226#ifdef BB_LOGNAME //usr/bin 236#ifdef BB_LOGNAME //usr/bin
227 {"logname", logname_main}, 237 {"logname", logname_main},
228#endif 238#endif
229#ifdef BB_SWAPONOFF //sbin 239#ifdef BB_SWAPONOFF //sbin
230 {"swapon", swap_on_off_main}, 240 {"swapon", swap_on_off_main},
231 {"swapoff", swap_on_off_main}, 241 {"swapoff", swap_on_off_main},
232#endif 242#endif
233#ifdef BB_TAIL //usr/bin 243#ifdef BB_TAIL //usr/bin
234 {"tail", tail_main}, 244 {"tail", tail_main},
235#endif 245#endif
236#ifdef BB_TAR //bin 246#ifdef BB_TAR //bin
237 {"tar", tar_main}, 247 {"tar", tar_main},
238#endif 248#endif
239#ifdef BB_TEE //bin 249#ifdef BB_TEE //bin
240 {"tee", tee_main}, 250 {"tee", tee_main},
241#endif 251#endif
242#ifdef BB_TOUCH //usr/bin 252#ifdef BB_TOUCH //usr/bin
243 {"touch", touch_main}, 253 {"touch", touch_main},
244#endif 254#endif
245#ifdef BB_TRUE_FALSE //bin 255#ifdef BB_TRUE_FALSE //bin
246 {"true", true_main}, 256 {"true", true_main},
247 {"false", false_main}, 257 {"false", false_main},
248#endif 258#endif
249#ifdef BB_TTY //usr/bin 259#ifdef BB_TTY //usr/bin
250 {"tty", tty_main}, 260 {"tty", tty_main},
251#endif 261#endif
252#ifdef BB_UNAME //bin 262#ifdef BB_UNAME //bin
253 {"uname", uname_main}, 263 {"uname", uname_main},
254#endif 264#endif
255#ifdef BB_UMOUNT //bin 265#ifdef BB_UMOUNT //bin
256 {"umount", umount_main}, 266 {"umount", umount_main},
257#endif 267#endif
258#ifdef BB_UNIQ //bin 268#ifdef BB_UNIQ //bin
259 {"uniq", uniq_main}, 269 {"uniq", uniq_main},
260#endif 270#endif
261#ifdef BB_UPDATE //sbin 271#ifdef BB_UPDATE //sbin
262 {"update", update_main}, 272 {"update", update_main},
263#endif 273#endif
264#ifdef BB_WC //usr/bin 274#ifdef BB_WC //usr/bin
265 {"wc", wc_main}, 275 {"wc", wc_main},
266#endif 276#endif
267#ifdef BB_WHOAMI //usr/bin 277#ifdef BB_WHOAMI //usr/bin
268 {"whoami", whoami_main}, 278 {"whoami", whoami_main},
269#endif 279#endif
270#ifdef BB_YES //usr/bin 280#ifdef BB_YES //usr/bin
271 {"yes", yes_main}, 281 {"yes", yes_main},
272#endif 282#endif
273#ifdef BB_GUNZIP //bin 283#ifdef BB_GUNZIP //bin
274 {"zcat", gunzip_main}, 284 {"zcat", gunzip_main},
275 {"gunzip", gunzip_main}, 285 {"gunzip", gunzip_main},
276#endif 286#endif
277#ifdef BB_GZIP //bin 287#ifdef BB_GZIP //bin
278 {"gzip", gzip_main}, 288 {"gzip", gzip_main},
279#endif 289#endif
280 {0} 290 {0}
281}; 291};
282 292
283 293
284 294
285int main(int argc, char **argv) 295int main(int argc, char **argv)
286{ 296{
287 char *s = argv[0]; 297 char *s = argv[0];
288 char *name = argv[0]; 298 char *name = argv[0];
289 const struct Applet *a = applets; 299 const struct Applet *a = applets;
290 300
291 while (*s != '\0') { 301 while (*s != '\0') {
292 if (*s++ == '/') 302 if (*s++ == '/')
293 name = s; 303 name = s;
294 } 304 }
295 305
296 while (a->name != 0) { 306 while (a->name != 0) {
297 if (strcmp(name, a->name) == 0) { 307 if (strcmp(name, a->name) == 0) {
298 int status; 308 int status;
299 309
300 status = ((*(a->main)) (argc, argv)); 310 status = ((*(a->main)) (argc, argv));
301 if (status < 0) { 311 if (status < 0) {
302 fprintf(stderr, "%s: %s\n", a->name, strerror(errno)); 312 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
303 } 313 }
304 fprintf(stderr, "\n"); 314 fprintf(stderr, "\n");
305 exit(status); 315 exit(status);
316 }
317 a++;
306 } 318 }
307 a++; 319 exit(busybox_main(argc, argv));
308 }
309 exit (busybox_main(argc, argv));
310} 320}
311 321
312 322
313int busybox_main(int argc, char **argv) 323int busybox_main(int argc, char **argv)
314{ 324{
315 int col=0; 325 int col = 0;
316 argc--;
317 argv++;
318 326
319 if (been_there_done_that == 1 || argc < 1) { 327 argc--;
320 const struct Applet *a = applets; 328 argv++;
321 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
322 BB_VER, BB_BT);
323 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
324 fprintf(stderr, " or: [function] [arguments]...\n\n");
325 fprintf(stderr,
326 "\tMost people will create a symlink to busybox for each\n"
327 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
328 fprintf(stderr, "\nCurrently defined functions:\n");
329 329
330 while (a->name != 0) { 330 if (been_there_done_that == 1 || argc < 1) {
331 col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name); 331 const struct Applet *a = applets;
332 if (col>60 && a->name != 0) { 332
333 fprintf(stderr, ",\n"); 333 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
334 col=0; 334 BB_VER, BB_BT);
335 } 335 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
336 fprintf(stderr, " or: [function] [arguments]...\n\n");
337 fprintf(stderr,
338 "\tMost people will create a symlink to busybox for each\n"
339 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
340 fprintf(stderr, "\nCurrently defined functions:\n");
341
342 while (a->name != 0) {
343 col +=
344 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
345 (a++)->name);
346 if (col > 60 && a->name != 0) {
347 fprintf(stderr, ",\n");
348 col = 0;
349 }
350 }
351 fprintf(stderr, "\n\n");
352 exit(-1);
353 } else {
354 /* If we've already been here once, exit now */
355 been_there_done_that = 1;
356 return (main(argc, argv));
336 } 357 }
337 fprintf(stderr, "\n\n");
338 exit(-1);
339 } else {
340 /* If we've already been here once, exit now */
341 been_there_done_that = 1;
342 return (main(argc, argv));
343 }
344} 358}