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
80 {"dmesg", dmesg_main},
85 #ifdef BB_DUTMP //usr/sbin
86 {"dutmp", dutmp_main},
88 #ifdef BB_FBSET //usr/sbin
89 {"fbset", fbset_main},
91 #ifdef BB_FDFLUSH //bin
92 {"fdflush", fdflush_main},
94 #ifdef BB_FIND //usr/bin
97 #ifdef BB_FREE //usr/bin
100 #ifdef BB_DEALLOCVT //usr/bin
101 {"deallocvt", deallocvt_main},
103 #ifdef BB_FSCK_MINIX //sbin
104 {"fsck.minix", fsck_minix_main},
106 #ifdef BB_MKFS_MINIX //sbin
107 {"mkfs.minix", mkfs_minix_main},
112 #ifdef BB_HALT //sbin
118 #ifdef BB_HOSTID //usr/bin
119 {"hostid", hostid_main},
121 #ifdef BB_HOSTNAME //bin
122 {"hostname", hostname_main},
124 #ifdef BB_INIT //sbin
127 #ifdef BB_INSMOD //sbin
128 {"insmod", insmod_main},
130 #ifdef BB_FEATURE_LINUXRC //
131 {"linuxrc", init_main},
136 #ifdef BB_LENGTH //usr/bin
137 {"length", length_main},
142 #ifdef BB_LOADACM //usr/bin
143 {"loadacm", loadacm_main},
145 #ifdef BB_LOADFONT //usr/bin
146 {"loadfont", loadfont_main},
148 #ifdef BB_LOADKMAP //sbin
149 {"loadkmap", loadkmap_main},
154 #ifdef BB_LSMOD //sbin
155 {"lsmod", lsmod_main},
157 #ifdef BB_MAKEDEVS //sbin
158 {"makedevs", makedevs_main},
160 #ifdef BB_MATH //usr/bin
163 #ifdef BB_MKDIR //bin
164 {"mkdir", mkdir_main},
166 #ifdef BB_MKFIFO //usr/bin
167 {"mkfifo", mkfifo_main},
169 #ifdef BB_MKNOD //bin
170 {"mknod", mknod_main},
172 #ifdef BB_MKSWAP //sbin
173 {"mkswap", mkswap_main},
175 #ifdef BB_MNC //usr/bin
181 #ifdef BB_MOUNT //bin
182 {"mount", mount_main},
187 #ifdef BB_NSLOOKUP //usr/bin
188 {"nslookup", nslookup_main},
193 #ifdef BB_POWEROFF //sbin
194 {"poweroff", poweroff_main},
196 #ifdef BB_PRINTF //usr/bin
197 {"printf", printf_main},
205 #ifdef BB_REBOOT //sbin
206 {"reboot", reboot_main},
211 #ifdef BB_RMDIR //bin
212 {"rmdir", rmdir_main},
214 #ifdef BB_RMMOD //sbin
215 {"rmmod", rmmod_main},
217 #ifdef BB_SFDISK //sbin
218 {"fdisk", sfdisk_main},
219 {"sfdisk", sfdisk_main},
224 #ifdef BB_SLEEP //bin
225 {"sleep", sleep_main},
233 #ifdef BB_SYSLOGD //sbin
234 {"syslogd", syslogd_main},
236 #ifdef BB_LOGGER //usr/bin
237 {"logger", logger_main},
239 #ifdef BB_LOGNAME //usr/bin
240 {"logname", logname_main},
242 #ifdef BB_SWAPONOFF //sbin
243 {"swapon", swap_on_off_main},
244 {"swapoff", swap_on_off_main},
246 #ifdef BB_TAIL //usr/bin
255 #ifdef BB_TOUCH //usr/bin
256 {"touch", touch_main},
258 #ifdef BB_TRUE_FALSE //bin
260 {"false", false_main},
262 #ifdef BB_TTY //usr/bin
265 #ifdef BB_UNAME //bin
266 {"uname", uname_main},
268 #ifdef BB_UMOUNT //bin
269 {"umount", umount_main},
274 #ifdef BB_UPDATE //sbin
275 {"update", update_main},
277 #ifdef BB_WC //usr/bin
280 #ifdef BB_WHOAMI //usr/bin
281 {"whoami", whoami_main},
283 #ifdef BB_YES //usr/bin
286 #ifdef BB_GUNZIP //bin
287 {"zcat", gunzip_main},
288 {"gunzip", gunzip_main},
298 int main(int argc, char **argv)
301 char *name = argv[0];
302 const struct Applet *a = applets;
309 while (a->name != 0) {
310 if (strcmp(name, a->name) == 0) {
313 status = ((*(a->main)) (argc, argv));
315 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
317 fprintf(stderr, "\n");
322 exit(busybox_main(argc, argv));
326 int busybox_main(int argc, char **argv)
333 if (been_there_done_that == 1 || argc < 1) {
334 const struct Applet *a = applets;
336 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
338 fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
339 fprintf(stderr, " or: [function] [arguments]...\n\n");
341 "\tMost people will create a symlink to busybox for each\n"
342 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
343 fprintf(stderr, "\nCurrently defined functions:\n");
345 while (a->name != 0) {
347 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
349 if (col > 60 && a->name != 0) {
350 fprintf(stderr, ",\n");
354 fprintf(stderr, "\n\n");
357 /* If we've already been here once, exit now */
358 been_there_done_that = 1;
359 return (main(argc, argv));