1 /* vi: set sw=4 ts=4: */
8 #ifdef CONFIG_LOCALE_SUPPORT
12 int been_there_done_that = 0; /* Also used in applets.c */
13 const char *bb_applet_name;
15 #ifdef CONFIG_FEATURE_INSTALLER
18 * this should be consistent w/ the enum, busybox.h::Location,
21 static const char usr_bin [] ="/usr/bin";
22 static const char usr_sbin[] ="/usr/sbin";
24 static const char* const install_dir[] = {
25 &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
26 &usr_bin [4], /* "/bin" */
27 &usr_sbin[4], /* "/sbin" */
33 typedef int (*__link_f)(const char *, const char *);
36 * Where in the filesystem is this busybox?
38 * malloc'd string w/ full pathname of busybox's location
41 static inline char *busybox_fullpath(void)
43 return xreadlink("/proc/self/exe");
46 /* create (sym)links for each applet */
47 static void install_links(const char *busybox, int use_symbolic_links)
55 if (use_symbolic_links)
58 for (i = 0; applets[i].name != NULL; i++) {
59 fpc = concat_path_file(
60 install_dir[applets[i].location], applets[i].name);
61 rc = Link(busybox, fpc);
62 if (rc!=0 && errno!=EEXIST) {
63 bb_perror_msg("%s", fpc);
69 #endif /* CONFIG_FEATURE_INSTALLER */
71 int main(int argc, char **argv)
75 bb_applet_name = argv[0];
77 if (bb_applet_name[0] == '-')
80 for (s = bb_applet_name; *s != '\0';) {
85 #ifdef CONFIG_LOCALE_SUPPORT
87 if(getpid()!=1) /* Do not set locale for `init' */
90 setlocale(LC_ALL, "");
94 run_applet_by_name(bb_applet_name, argc, argv);
95 bb_error_msg_and_die("applet not found");
99 int busybox_main(int argc, char **argv)
103 #ifdef CONFIG_FEATURE_INSTALLER
105 * This style of argument parsing doesn't scale well
106 * in the event that busybox starts wanting more --options.
107 * If someone has a cleaner approach, by all means implement it.
109 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
110 int use_symbolic_links = 0;
114 /* to use symlinks, or not to use symlinks... */
116 if ((strcmp(argv[2], "-s") == 0)) {
117 use_symbolic_links = 1;
122 busybox = busybox_fullpath();
124 install_links(busybox, use_symbolic_links);
131 #endif /* CONFIG_FEATURE_INSTALLER */
135 /* If we've already been here once, exit now */
136 if (been_there_done_that == 1 || argc < 1) {
137 const struct BB_applet *a = applets;
139 fprintf(stderr, "%s\n\n"
140 "Usage: busybox [function] [arguments]...\n"
141 " or: [function] [arguments]...\n\n"
142 "\tBusyBox is a multi-call binary that combines many common Unix\n"
143 "\tutilities into a single executable. Most people will create a\n"
144 "\tlink to busybox for each function they wish to use, and BusyBox\n"
145 "\twill act like whatever it was invoked as.\n"
146 "\nCurrently defined functions:\n", bb_msg_full_version);
148 while (a->name != 0) {
150 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
152 if (col > 60 && a->name != 0) {
153 fprintf(stderr, ",\n");
157 fprintf(stderr, "\n\n");
161 /* Flag that we've been here already */
162 been_there_done_that = 1;
164 /* Move the command line down a notch */
165 return (main(argc, argv+1));
170 c-file-style: "linux"