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()
42 sprintf(proc, "/proc/%d/exe", getpid());
43 return xreadlink(proc);
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 perror_msg("%s", fpc);
69 #endif /* BB_FEATURE_INSTALLER */
71 int main(int argc, char **argv)
75 for (s = applet_name = argv[0]; *s != '\0';) {
81 /* Add in a special case hack -- whenever **argv == '-'
82 * (i.e. '-su' or '-sh') always invoke the shell */
83 if (**argv == '-' && *(*argv+1)!= '-') {
88 #ifdef BB_LOCALE_SUPPORT
89 if(getpid()!=1) /* Do not set locale for `init' */
90 setlocale(LC_ALL, "");
93 run_applet_by_name(applet_name, argc, argv);
94 error_msg_and_die("applet not found");
98 int busybox_main(int argc, char **argv)
102 #ifdef BB_FEATURE_INSTALLER
104 * This style of argument parsing doesn't scale well
105 * in the event that busybox starts wanting more --options.
106 * If someone has a cleaner approach, by all means implement it.
108 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
109 int use_symbolic_links = 0;
113 /* to use symlinks, or not to use symlinks... */
115 if ((strcmp(argv[2], "-s") == 0)) {
116 use_symbolic_links = 1;
121 busybox = busybox_fullpath();
123 install_links(busybox, use_symbolic_links);
130 #endif /* BB_FEATURE_INSTALLER */
134 /* If we've already been here once, exit now */
135 if (been_there_done_that == 1 || argc < 1) {
136 const struct BB_applet *a = applets;
138 fprintf(stderr, "%s\n\n"
139 "Usage: busybox [function] [arguments]...\n"
140 " or: [function] [arguments]...\n\n"
141 "\tBusyBox is a multi-call binary that combines many common Unix\n"
142 "\tutilities into a single executable. Most people will create a\n"
143 "\tlink to busybox for each function they wish to use, and BusyBox\n"
144 "\twill act like whatever it was invoked as.\n"
145 "\nCurrently defined functions:\n", full_version);
147 while (a->name != 0) {
149 fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
151 if (col > 60 && a->name != 0) {
152 fprintf(stderr, ",\n");
156 fprintf(stderr, "\n\n");
160 /* Flag that we've been here already */
161 been_there_done_that = 1;
163 /* Move the command line down a notch */
164 len = argv[argc] + strlen(argv[argc]) - argv[1];
165 memmove(argv[0], argv[1], len);
166 memset(argv[0] + len, 0, argv[1] - argv[0]);
168 /* Fix up the argv pointers */
169 len = argv[1] - argv[0];
170 memmove(argv, argv + 1, sizeof(char *) * (argc + 1));
171 for (i = 0; i < argc; i++)
174 return (main(argc, argv));
179 c-file-style: "linux"