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_BASENAME //usr/bin/basename
41 {"basename", basename_main},
43 #ifdef BB_BUSYBOX //bin
44 {"busybox", busybox_main},
46 #ifdef BB_BLOCK_DEVICE //sbin
47 {"block_device", block_device_main},
52 #ifdef BB_CHMOD_CHOWN_CHGRP //bin
53 {"chmod", chmod_chown_chgrp_main},
54 {"chown", chmod_chown_chgrp_main},
55 {"chgrp", chmod_chown_chgrp_main},
57 #ifdef BB_CHROOT //sbin
58 {"chroot", chroot_main},
60 #ifdef BB_CLEAR //usr/bin
61 {"clear", clear_main},
63 #ifdef BB_CHVT //usr/bin
79 #ifdef BB_DIRNAME //usr/bin
80 {"dirname", dirname_main},
83 {"dmesg", dmesg_main},
88 #ifdef BB_DUTMP //usr/sbin
89 {"dutmp", dutmp_main},
91 #ifdef BB_FBSET //usr/sbin
92 {"fbset", fbset_main},
94 #ifdef BB_FDFLUSH //bin
95 {"fdflush", fdflush_main},
97 #ifdef BB_FIND //usr/bin
100 #ifdef BB_FREE //usr/bin
103 #ifdef BB_FREERAMDISK //sbin
104 {"freeramdisk", freeramdisk_main},
106 #ifdef BB_DEALLOCVT //usr/bin
107 {"deallocvt", deallocvt_main},
109 #ifdef BB_FSCK_MINIX //sbin
110 {"fsck.minix", fsck_minix_main},
112 #ifdef BB_MKFS_MINIX //sbin
113 {"mkfs.minix", mkfs_minix_main},
118 #ifdef BB_HALT //sbin
124 #ifdef BB_HOSTID //usr/bin
125 {"hostid", hostid_main},
127 #ifdef BB_HOSTNAME //bin
128 {"hostname", hostname_main},
130 #ifdef BB_INIT //sbin
133 #ifdef BB_INSMOD //sbin
134 {"insmod", insmod_main},
136 #ifdef BB_FEATURE_LINUXRC //
137 {"linuxrc", init_main},
142 #ifdef BB_KILLALL //usr/bin
143 {"killall", kill_main},
145 #ifdef BB_LENGTH //usr/bin
146 {"length", length_main},
151 #ifdef BB_LOADACM //usr/bin
152 {"loadacm", loadacm_main},
154 #ifdef BB_LOADFONT //usr/bin
155 {"loadfont", loadfont_main},
157 #ifdef BB_LOADKMAP //sbin
158 {"loadkmap", loadkmap_main},
163 #ifdef BB_LSMOD //sbin
164 {"lsmod", lsmod_main},
166 #ifdef BB_MAKEDEVS //sbin
167 {"makedevs", makedevs_main},
169 #ifdef BB_MATH //usr/bin
172 #ifdef BB_MKDIR //bin
173 {"mkdir", mkdir_main},
175 #ifdef BB_MKFIFO //usr/bin
176 {"mkfifo", mkfifo_main},
178 #ifdef BB_MKNOD //bin
179 {"mknod", mknod_main},
181 #ifdef BB_MKSWAP //sbin
182 {"mkswap", mkswap_main},
184 #ifdef BB_MNC //usr/bin
190 #ifdef BB_MOUNT //bin
191 {"mount", mount_main},
196 #ifdef BB_NSLOOKUP //usr/bin
197 {"nslookup", nslookup_main},
202 #ifdef BB_POWEROFF //sbin
203 {"poweroff", poweroff_main},
205 #ifdef BB_PRINTF //usr/bin
206 {"printf", printf_main},
214 #ifdef BB_REBOOT //sbin
215 {"reboot", reboot_main},
220 #ifdef BB_RMDIR //bin
221 {"rmdir", rmdir_main},
223 #ifdef BB_RMMOD //sbin
224 {"rmmod", rmmod_main},
232 #ifdef BB_SFDISK //sbin
233 {"fdisk", sfdisk_main},
234 {"sfdisk", sfdisk_main},
236 #ifdef BB_SLEEP //bin
237 {"sleep", sleep_main},
245 #ifdef BB_SYSLOGD //sbin
246 {"syslogd", syslogd_main},
248 #ifdef BB_LOGGER //usr/bin
249 {"logger", logger_main},
251 #ifdef BB_LOGNAME //usr/bin
252 {"logname", logname_main},
254 #ifdef BB_SWAPONOFF //sbin
255 {"swapon", swap_on_off_main},
256 {"swapoff", swap_on_off_main},
258 #ifdef BB_TAIL //usr/bin
264 #ifdef BB_TELNET //usr/bin
265 {"telnet", telnet_main},
270 #ifdef BB_TOUCH //usr/bin
271 {"touch", touch_main},
273 #ifdef BB_TR //usr/bin
276 #ifdef BB_TRUE_FALSE //bin
278 {"false", false_main},
280 #ifdef BB_TTY //usr/bin
283 #ifdef BB_UMOUNT //bin
284 {"umount", umount_main},
286 #ifdef BB_UNAME //bin
287 {"uname", uname_main},
289 #ifdef BB_UPTIME //usr/bin
290 {"uptime", uptime_main},
295 #ifdef BB_UPDATE //sbin
296 {"update", update_main},
298 #ifdef BB_WC //usr/bin
301 #ifdef BB_WHOAMI //usr/bin
302 {"whoami", whoami_main},
304 #ifdef BB_YES //usr/bin
307 #ifdef BB_GUNZIP //bin
308 {"zcat", gunzip_main},
309 {"gunzip", gunzip_main},
319 int main(int argc, char **argv)
322 char *name = argv[0];
323 const struct Applet *a = applets;
332 while (a->name != 0) {
333 if (strcmp(name, a->name) == 0) {
336 status = ((*(a->main)) (argc, argv));
338 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
340 fprintf(stderr, "\n");
345 exit(busybox_main(argc, argv));
349 int busybox_main(int argc, char **argv)
356 if (been_there_done_that == 1 || argc < 1) {
357 const struct Applet *a = applets;
359 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
361 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
362 fprintf(stderr, " or: [function] [arguments]...\n\n");
364 "\tMost people will create a link to busybox for each\n"
365 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
366 fprintf(stderr, "\nCurrently defined functions:\n");
368 while (a->name != 0) {
370 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
372 if (col > 60 && a->name != 0) {
373 fprintf(stderr, ",\n");
377 fprintf(stderr, "\n\n");
380 /* If we've already been here once, exit now */
381 been_there_done_that = 1;
382 return (main(argc, argv));
388 c-file-style: "linux"