summaryrefslogtreecommitdiff
path: root/applets/busybox.c
diff options
context:
space:
mode:
Diffstat (limited to 'applets/busybox.c')
-rw-r--r--applets/busybox.c158
1 files changed, 0 insertions, 158 deletions
diff --git a/applets/busybox.c b/applets/busybox.c
deleted file mode 100644
index 47a8b4097..000000000
--- a/applets/busybox.c
+++ /dev/null
@@ -1,158 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * BusyBox' main applet dispatcher.
4 *
5 * Licensed under GPLv2, see file LICENSE in this tarball for details.
6 */
7#include "busybox.h"
8
9const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
10#ifdef BB_NOMMU
11smallint re_execed;
12#endif
13
14#ifdef CONFIG_FEATURE_INSTALLER
15/*
16 * directory table
17 * this should be consistent w/ the enum, busybox.h::Location,
18 * or else...
19 */
20static const char usr_bin [] = "/usr/bin";
21static const char usr_sbin[] = "/usr/sbin";
22
23static const char* const install_dir[] = {
24 &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
25 &usr_bin [4], /* "/bin" */
26 &usr_sbin[4], /* "/sbin" */
27 usr_bin,
28 usr_sbin
29};
30
31/* abstract link() */
32typedef int (*link_func)(const char *, const char *);
33
34/* create (sym)links for each applet */
35static void install_links(const char *busybox, int use_symbolic_links)
36{
37 link_func lf = link;
38 char *fpc;
39 int i;
40 int rc;
41
42 if (use_symbolic_links)
43 lf = symlink;
44
45 for (i = 0; applets[i].name != NULL; i++) {
46 fpc = concat_path_file(
47 install_dir[applets[i].location],
48 applets[i].name);
49 rc = lf(busybox, fpc);
50 if (rc != 0 && errno != EEXIST) {
51 bb_perror_msg("%s", fpc);
52 }
53 free(fpc);
54 }
55}
56
57#else
58#define install_links(x,y)
59#endif /* CONFIG_FEATURE_INSTALLER */
60
61int main(int argc, char **argv)
62{
63 const char *s;
64
65#ifdef BB_NOMMU
66 /* NOMMU re-exec trick sets high-order bit in first byte of name */
67 if (argv[0][0] & 0x80) {
68 re_execed = 1;
69 argv[0][0] &= 0x7f;
70 }
71#endif
72
73 applet_name = argv[0];
74 if (*applet_name == '-')
75 applet_name++;
76 while ((s = strchr(applet_name, '/')))
77 applet_name = s + 1;
78
79 /* Set locale for everybody except 'init' */
80 if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
81 setlocale(LC_ALL, "");
82
83 run_applet_by_name(applet_name, argc, argv);
84 bb_error_msg_and_die("applet not found");
85}
86
87int busybox_main(int argc, char **argv);
88int busybox_main(int argc, char **argv)
89{
90 /*
91 * This style of argument parsing doesn't scale well
92 * in the event that busybox starts wanting more --options.
93 * If someone has a cleaner approach, by all means implement it.
94 */
95 if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
96 int use_symbolic_links = 0;
97 char *busybox;
98
99 /* to use symlinks, or not to use symlinks... */
100 if (argc > 2)
101 if (strcmp(argv[2], "-s") == 0)
102 use_symbolic_links = 1;
103
104 /* link */
105// XXX: FIXME: this is broken. Why not just use argv[0] ?
106 busybox = xmalloc_readlink_or_warn("/proc/self/exe");
107 if (!busybox)
108 return 1;
109 install_links(busybox, use_symbolic_links);
110 if (ENABLE_FEATURE_CLEAN_UP)
111 free(busybox);
112 return 0;
113 }
114
115 /* Deal with --help. (Also print help when called with no arguments) */
116
117 if (argc == 1 || !strcmp(argv[1], "--help") ) {
118 if (argc > 2) {
119 applet_name = argv[2];
120 run_applet_by_name(applet_name, 2, argv);
121 } else {
122 const struct BB_applet *a;
123 int col, output_width;
124
125 output_width = 80 - sizeof("start-stop-daemon, ") - 8;
126 if (ENABLE_FEATURE_AUTOWIDTH) {
127 /* Obtain the terminal width. */
128 get_terminal_width_height(0, &output_width, NULL);
129 /* leading tab and room to wrap */
130 output_width -= sizeof("start-stop-daemon, ") + 8;
131 }
132
133 printf("%s\n"
134 "Copyright (C) 1998-2006  Erik Andersen, Rob Landley, and others.\n"
135 "Licensed under GPLv2.  See source distribution for full notice.\n\n"
136 "Usage: busybox [function] [arguments]...\n"
137 " or: [function] [arguments]...\n\n"
138 "\tBusyBox is a multi-call binary that combines many common Unix\n"
139 "\tutilities into a single executable. Most people will create a\n"
140 "\tlink to busybox for each function they wish to use and BusyBox\n"
141 "\twill act like whatever it was invoked as!\n"
142 "\nCurrently defined functions:\n", bb_msg_full_version);
143 col = 0;
144 for (a = applets; a->name;) {
145 col += printf("%s%s", (col ? ", " : "\t"), a->name);
146 a++;
147 if (col > output_width && a->name) {
148 puts(",");
149 col = 0;
150 }
151 }
152 puts("\n");
153 return 0;
154 }
155 } else run_applet_by_name(argv[1], argc - 1, argv + 1);
156
157 bb_error_msg_and_die("applet not found");
158}