1 /* vi: set sw=4 ts=4: */
8 #ifdef BB_LOCALE_SUPPORT
12 int been_there_done_that = 0; /* Also used in applets.c */
13 const char *applet_name;
15 #ifdef BB_FEATURE_INSTALLER
18 * this should be consistent w/ the enum, busybox.h::Location,
21 static char* install_dir[] = {
30 typedef int (*__link_f)(const char *, const char *);
33 * Where in the filesystem is this busybox?
35 * malloc'd string w/ full pathname of busybox's location
38 static char *busybox_fullpath()
40 return xreadlink("/proc/self/exe");
43 /* create (sym)links for each applet */
44 static void install_links(const char *busybox, int use_symbolic_links)
52 if (use_symbolic_links)
55 for (i = 0; applets[i].name != NULL; i++) {
56 fpc = concat_path_file(
57 install_dir[applets[i].location], applets[i].name);
58 rc = Link(busybox, fpc);
59 if (rc!=0 && errno!=EEXIST) {
60 perror_msg("%s", fpc);
66 #endif /* BB_FEATURE_INSTALLER */
68 int main(int argc, char **argv)
72 for (s = applet_name = argv[0]; *s != '\0';) {
77 /* Add in a special case hack for a leading hyphen */
78 if (**argv == '-' && *(*argv+1)!= '-') {
79 applet_name = (*argv+1);
82 #ifdef BB_LOCALE_SUPPORT
84 if(getpid()!=1) /* Do not set locale for `init' */
87 setlocale(LC_ALL, "");
91 run_applet_by_name(applet_name, argc, argv);
92 error_msg_and_die("applet not found");
96 int busybox_main(int argc, char **argv)
100 #ifdef BB_FEATURE_INSTALLER
102 * This style of argument parsing doesn't scale well
103 * in the event that busybox starts wanting more --options.
104 * If someone has a cleaner approach, by all means implement it.
106 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
107 int use_symbolic_links = 0;
111 /* to use symlinks, or not to use symlinks... */
113 if ((strcmp(argv[2], "-s") == 0)) {
114 use_symbolic_links = 1;
119 busybox = busybox_fullpath();
121 install_links(busybox, use_symbolic_links);
128 #endif /* BB_FEATURE_INSTALLER */
132 /* If we've already been here once, exit now */
133 if (been_there_done_that == 1 || argc < 1) {
134 const struct BB_applet *a = applets;
136 fprintf(stderr, "%s\n\n"
137 "Usage: busybox [function] [arguments]...\n"
138 " or: [function] [arguments]...\n\n"
139 "\tBusyBox is a multi-call binary that combines many common Unix\n"
140 "\tutilities into a single executable. Most people will create a\n"
141 "\tlink to busybox for each function they wish to use, and BusyBox\n"
142 "\twill act like whatever it was invoked as.\n"
143 "\nCurrently defined functions:\n", full_version);
145 while (a->name != 0) {
147 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
149 if (col > 60 && a->name != 0) {
150 fprintf(stderr, ",\n");
154 fprintf(stderr, "\n\n");
158 /* Flag that we've been here already */
159 been_there_done_that = 1;
161 /* Move the command line down a notch */
162 len = argv[argc] + strlen(argv[argc]) - argv[1];
163 memmove(argv[0], argv[1], len);
164 memset(argv[0] + len, 0, argv[1] - argv[0]);
166 /* Fix up the argv pointers */
167 len = argv[1] - argv[0];
168 memmove(argv, argv + 1, sizeof(char *) * (argc + 1));
169 for (i = 0; i < argc; i++)
172 return (main(argc, argv));
177 c-file-style: "linux"