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';) {
78 /* Add in a special case hack -- whenever **argv == '-'
79 * (i.e., '-su' or '-sh') always invoke the shell */
80 if (**argv == '-' && *(*argv+1)!= '-') {
85 #ifdef BB_LOCALE_SUPPORT
87 if(getpid()!=1) /* Do not set locale for `init' */
90 setlocale(LC_ALL, "");
94 run_applet_by_name(applet_name, argc, argv);
95 error_msg_and_die("applet not found");
99 int busybox_main(int argc, char **argv)
103 #ifdef BB_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 /* BB_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", 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 len = argv[argc] + strlen(argv[argc]) - argv[1];
166 memmove(argv[0], argv[1], len);
167 memset(argv[0] + len, 0, argv[1] - argv[0]);
169 /* Fix up the argv pointers */
170 len = argv[1] - argv[0];
171 memmove(argv, argv + 1, sizeof(char *) * (argc + 1));
172 for (i = 0; i < argc; i++)
175 return (main(argc, argv));
180 c-file-style: "linux"