1 /* vi: set sw=4 ts=4: */
8 #undef BB_FEATURE_LINUXRC
11 static int been_there_done_that = 0;
13 /* It has been alledged that doing such things can
14 * help reduce binary size when staticly linking,
15 * of course with glibc, this is unlikely as long
16 * as we use things like printf -- perhaps a printf
17 * replacement may be in order
20 void exit(int status) __attribute__ ((noreturn));
25 void abort(void) __attribute__ ((__noreturn__));
30 int atexit(void (*__func) (void))
34 void *__libc_stack_end;
38 static const struct Applet applets[] = {
40 #ifdef BB_BUSYBOX //bin
41 {"busybox", busybox_main},
43 #ifdef BB_BLOCK_DEVICE //sbin
44 {"block_device", block_device_main},
49 #ifdef BB_CHMOD_CHOWN_CHGRP //bin
50 {"chmod", chmod_chown_chgrp_main},
51 {"chown", chmod_chown_chgrp_main},
52 {"chgrp", chmod_chown_chgrp_main},
54 #ifdef BB_CHROOT //sbin
55 {"chroot", chroot_main},
57 #ifdef BB_CLEAR //usr/bin
58 {"clear", clear_main},
60 #ifdef BB_CHVT //usr/bin
77 {"dmesg", dmesg_main},
82 #ifdef BB_DUTMP //usr/sbin
83 {"dutmp", dutmp_main},
85 #ifdef BB_FBSET //usr/sbin
86 {"fbset", fbset_main},
88 #ifdef BB_FDFLUSH //bin
89 {"fdflush", fdflush_main},
91 #ifdef BB_FIND //usr/bin
94 #ifdef BB_FREE //usr/bin
97 #ifdef BB_DEALLOCVT //usr/bin
98 {"deallocvt", deallocvt_main},
100 #ifdef BB_FSCK_MINIX //sbin
101 {"fsck.minix", fsck_minix_main},
103 #ifdef BB_MKFS_MINIX //sbin
104 {"mkfs.minix", mkfs_minix_main},
109 #ifdef BB_HALT //sbin
115 #ifdef BB_HOSTID //usr/bin
116 {"hostid", hostid_main},
118 #ifdef BB_HOSTNAME //bin
119 {"hostname", hostname_main},
121 #ifdef BB_INIT //sbin
124 #ifdef BB_INSMOD //sbin
125 {"insmod", insmod_main},
127 #ifdef BB_FEATURE_LINUXRC //
128 {"linuxrc", init_main},
133 #ifdef BB_LENGTH //usr/bin
134 {"length", length_main},
139 #ifdef BB_LOADACM //usr/bin
140 {"loadacm", loadacm_main},
142 #ifdef BB_LOADFONT //usr/bin
143 {"loadfont", loadfont_main},
145 #ifdef BB_LOADKMAP //sbin
146 {"loadkmap", loadkmap_main},
151 #ifdef BB_LSMOD //sbin
152 {"lsmod", lsmod_main},
154 #ifdef BB_MAKEDEVS //sbin
155 {"makedevs", makedevs_main},
157 #ifdef BB_MATH //usr/bin
160 #ifdef BB_MKDIR //bin
161 {"mkdir", mkdir_main},
163 #ifdef BB_MKFIFO //usr/bin
164 {"mkfifo", mkfifo_main},
166 #ifdef BB_MKNOD //bin
167 {"mknod", mknod_main},
169 #ifdef BB_MKSWAP //sbin
170 {"mkswap", mkswap_main},
172 #ifdef BB_MNC //usr/bin
178 #ifdef BB_MOUNT //bin
179 {"mount", mount_main},
184 #ifdef BB_NSLOOKUP //usr/bin
185 {"nslookup", nslookup_main},
190 #ifdef BB_POWEROFF //sbin
191 {"poweroff", poweroff_main},
193 #ifdef BB_PRINTF //usr/bin
194 {"printf", printf_main},
202 #ifdef BB_REBOOT //sbin
203 {"reboot", reboot_main},
208 #ifdef BB_RMDIR //bin
209 {"rmdir", rmdir_main},
211 #ifdef BB_RMMOD //sbin
212 {"rmmod", rmmod_main},
214 #ifdef BB_SFDISK //sbin
215 {"fdisk", sfdisk_main},
216 {"sfdisk", sfdisk_main},
221 #ifdef BB_SLEEP //bin
222 {"sleep", sleep_main},
230 #ifdef BB_SYSLOGD //sbin
231 {"syslogd", syslogd_main},
233 #ifdef BB_LOGGER //usr/bin
234 {"logger", logger_main},
236 #ifdef BB_LOGNAME //usr/bin
237 {"logname", logname_main},
239 #ifdef BB_SWAPONOFF //sbin
240 {"swapon", swap_on_off_main},
241 {"swapoff", swap_on_off_main},
243 #ifdef BB_TAIL //usr/bin
252 #ifdef BB_TOUCH //usr/bin
253 {"touch", touch_main},
255 #ifdef BB_TRUE_FALSE //bin
257 {"false", false_main},
259 #ifdef BB_TTY //usr/bin
262 #ifdef BB_UNAME //bin
263 {"uname", uname_main},
265 #ifdef BB_UMOUNT //bin
266 {"umount", umount_main},
271 #ifdef BB_UPDATE //sbin
272 {"update", update_main},
274 #ifdef BB_WC //usr/bin
277 #ifdef BB_WHOAMI //usr/bin
278 {"whoami", whoami_main},
280 #ifdef BB_YES //usr/bin
283 #ifdef BB_GUNZIP //bin
284 {"zcat", gunzip_main},
285 {"gunzip", gunzip_main},
295 int main(int argc, char **argv)
298 char *name = argv[0];
299 const struct Applet *a = applets;
306 while (a->name != 0) {
307 if (strcmp(name, a->name) == 0) {
310 status = ((*(a->main)) (argc, argv));
312 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
314 fprintf(stderr, "\n");
319 exit(busybox_main(argc, argv));
323 int busybox_main(int argc, char **argv)
330 if (been_there_done_that == 1 || argc < 1) {
331 const struct Applet *a = applets;
333 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
335 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
336 fprintf(stderr, " or: [function] [arguments]...\n\n");
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");
342 while (a->name != 0) {
344 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
346 if (col > 60 && a->name != 0) {
347 fprintf(stderr, ",\n");
351 fprintf(stderr, "\n\n");
354 /* If we've already been here once, exit now */
355 been_there_done_that = 1;
356 return (main(argc, argv));