diff options
Diffstat (limited to 'applets')
-rw-r--r-- | applets/applets.c | 18 | ||||
-rw-r--r-- | applets/busybox.c | 66 |
2 files changed, 42 insertions, 42 deletions
diff --git a/applets/applets.c b/applets/applets.c index f8abb2767..ebd1ff313 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -44,7 +44,7 @@ static const char usage_messages[] = | |||
44 | static struct BB_applet *applet_using; | 44 | static struct BB_applet *applet_using; |
45 | 45 | ||
46 | /* The -1 arises because of the {0,NULL,0,-1} entry above. */ | 46 | /* The -1 arises because of the {0,NULL,0,-1} entry above. */ |
47 | const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1); | 47 | const unsigned short NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1); |
48 | 48 | ||
49 | 49 | ||
50 | #ifdef CONFIG_FEATURE_SUID_CONFIG | 50 | #ifdef CONFIG_FEATURE_SUID_CONFIG |
@@ -459,8 +459,6 @@ static int applet_name_compare(const void *name, const void *vapplet) | |||
459 | return strcmp(name, applet->name); | 459 | return strcmp(name, applet->name); |
460 | } | 460 | } |
461 | 461 | ||
462 | extern const size_t NUM_APPLETS; | ||
463 | |||
464 | struct BB_applet *find_applet_by_name(const char *name) | 462 | struct BB_applet *find_applet_by_name(const char *name) |
465 | { | 463 | { |
466 | return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), | 464 | return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), |
@@ -469,15 +467,19 @@ struct BB_applet *find_applet_by_name(const char *name) | |||
469 | 467 | ||
470 | void run_applet_by_name(const char *name, int argc, char **argv) | 468 | void run_applet_by_name(const char *name, int argc, char **argv) |
471 | { | 469 | { |
472 | if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file(); | 470 | if (ENABLE_FEATURE_SUID_CONFIG) |
471 | parse_config_file(); | ||
473 | 472 | ||
474 | if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv); | 473 | if (!strncmp(name, "busybox", 7)) |
474 | exit(busybox_main(argc, argv)); | ||
475 | /* Do a binary search to find the applet entry given the name. */ | 475 | /* Do a binary search to find the applet entry given the name. */ |
476 | applet_using = find_applet_by_name(name); | 476 | applet_using = find_applet_by_name(name); |
477 | if (applet_using) { | 477 | if (applet_using) { |
478 | applet_name = applet_using->name; | 478 | applet_name = applet_using->name; |
479 | if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage(); | 479 | if (argc == 2 && !strcmp(argv[1], "--help")) |
480 | if(ENABLE_FEATURE_SUID) check_suid(applet_using); | 480 | bb_show_usage(); |
481 | exit((*(applet_using->main))(argc, argv)); | 481 | if (ENABLE_FEATURE_SUID) |
482 | check_suid(applet_using); | ||
483 | exit(applet_using->main(argc, argv)); | ||
482 | } | 484 | } |
483 | } | 485 | } |
diff --git a/applets/busybox.c b/applets/busybox.c index bb9eb3af7..9ca12ac2b 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -14,8 +14,8 @@ const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; | |||
14 | * this should be consistent w/ the enum, busybox.h::Location, | 14 | * this should be consistent w/ the enum, busybox.h::Location, |
15 | * or else... | 15 | * or else... |
16 | */ | 16 | */ |
17 | static const char usr_bin [] ="/usr/bin"; | 17 | static const char usr_bin [] = "/usr/bin"; |
18 | static const char usr_sbin[] ="/usr/sbin"; | 18 | static const char usr_sbin[] = "/usr/sbin"; |
19 | 19 | ||
20 | static const char* const install_dir[] = { | 20 | static const char* const install_dir[] = { |
21 | &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */ | 21 | &usr_bin [8], /* "", equivalent to "/" for concat_path_file() */ |
@@ -26,25 +26,25 @@ static const char* const install_dir[] = { | |||
26 | }; | 26 | }; |
27 | 27 | ||
28 | /* abstract link() */ | 28 | /* abstract link() */ |
29 | typedef int (*__link_f)(const char *, const char *); | 29 | typedef int (*link_func)(const char *, const char *); |
30 | 30 | ||
31 | /* create (sym)links for each applet */ | 31 | /* create (sym)links for each applet */ |
32 | static void install_links(const char *busybox, int use_symbolic_links) | 32 | static void install_links(const char *busybox, int use_symbolic_links) |
33 | { | 33 | { |
34 | __link_f Link = link; | 34 | link_func lf = link; |
35 | |||
36 | char *fpc; | 35 | char *fpc; |
37 | int i; | 36 | int i; |
38 | int rc; | 37 | int rc; |
39 | 38 | ||
40 | if (use_symbolic_links) | 39 | if (use_symbolic_links) |
41 | Link = symlink; | 40 | lf = symlink; |
42 | 41 | ||
43 | for (i = 0; applets[i].name != NULL; i++) { | 42 | for (i = 0; applets[i].name != NULL; i++) { |
44 | fpc = concat_path_file( | 43 | fpc = concat_path_file( |
45 | install_dir[applets[i].location], applets[i].name); | 44 | install_dir[applets[i].location], |
46 | rc = Link(busybox, fpc); | 45 | applets[i].name); |
47 | if (rc!=0 && errno!=EEXIST) { | 46 | rc = lf(busybox, fpc); |
47 | if (rc != 0 && errno != EEXIST) { | ||
48 | bb_perror_msg("%s", fpc); | 48 | bb_perror_msg("%s", fpc); |
49 | } | 49 | } |
50 | free(fpc); | 50 | free(fpc); |
@@ -59,10 +59,11 @@ int main(int argc, char **argv) | |||
59 | { | 59 | { |
60 | const char *s; | 60 | const char *s; |
61 | 61 | ||
62 | applet_name=argv[0]; | 62 | applet_name = argv[0]; |
63 | if (*applet_name == '-') applet_name++; | 63 | if (*applet_name == '-') |
64 | for (s = applet_name; *s ;) | 64 | applet_name++; |
65 | if (*(s++) == '/') applet_name = s; | 65 | while ((s = strchr(applet_name, '/'))) |
66 | applet_name = s + 1; | ||
66 | 67 | ||
67 | /* Set locale for everybody except 'init' */ | 68 | /* Set locale for everybody except 'init' */ |
68 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) | 69 | if (ENABLE_LOCALE_SUPPORT && getpid() != 1) |
@@ -81,44 +82,41 @@ int busybox_main(int argc, char **argv) | |||
81 | */ | 82 | */ |
82 | if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) { | 83 | if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) { |
83 | int use_symbolic_links = 0; | 84 | int use_symbolic_links = 0; |
84 | int rc = 0; | ||
85 | char *busybox; | 85 | char *busybox; |
86 | 86 | ||
87 | /* to use symlinks, or not to use symlinks... */ | 87 | /* to use symlinks, or not to use symlinks... */ |
88 | if (argc > 2) { | 88 | if (argc > 2) |
89 | if ((strcmp(argv[2], "-s") == 0)) { | 89 | if (strcmp(argv[2], "-s") == 0) |
90 | use_symbolic_links = 1; | 90 | use_symbolic_links = 1; |
91 | } | ||
92 | } | ||
93 | 91 | ||
94 | /* link */ | 92 | /* link */ |
95 | // XXX: FIXME: this is broken. Why not just use argv[0] ? | 93 | // XXX: FIXME: this is broken. Why not just use argv[0] ? |
96 | busybox = xreadlink("/proc/self/exe"); | 94 | busybox = xreadlink("/proc/self/exe"); |
97 | if (busybox) { | 95 | if (!busybox) |
98 | install_links(busybox, use_symbolic_links); | 96 | return 1; |
97 | install_links(busybox, use_symbolic_links); | ||
98 | if (ENABLE_FEATURE_CLEAN_UP) | ||
99 | free(busybox); | 99 | free(busybox); |
100 | } else { | 100 | return 0; |
101 | rc = 1; | ||
102 | } | ||
103 | return rc; | ||
104 | } | 101 | } |
105 | 102 | ||
106 | /* Deal with --help. (Also print help when called with no arguments) */ | 103 | /* Deal with --help. (Also print help when called with no arguments) */ |
107 | 104 | ||
108 | if (argc==1 || !strcmp(argv[1],"--help") ) { | 105 | if (argc == 1 || !strcmp(argv[1], "--help") ) { |
109 | if (argc>2) { | 106 | if (argc > 2) { |
110 | applet_name = argv[2]; | 107 | applet_name = argv[2]; |
111 | run_applet_by_name(applet_name, 2, argv); | 108 | run_applet_by_name(applet_name, 2, argv); |
112 | } else { | 109 | } else { |
113 | const struct BB_applet *a; | 110 | const struct BB_applet *a; |
114 | int col, output_width; | 111 | int col, output_width; |
115 | 112 | ||
113 | output_width = 80 - sizeof("start-stop-daemon, ") - 8; | ||
116 | if (ENABLE_FEATURE_AUTOWIDTH) { | 114 | if (ENABLE_FEATURE_AUTOWIDTH) { |
117 | /* Obtain the terminal width. */ | 115 | /* Obtain the terminal width. */ |
118 | get_terminal_width_height(0, &output_width, NULL); | 116 | get_terminal_width_height(0, &output_width, NULL); |
119 | /* leading tab and room to wrap */ | 117 | /* leading tab and room to wrap */ |
120 | output_width -= sizeof("start-stop-daemon, ") + 8; | 118 | output_width -= sizeof("start-stop-daemon, ") + 8; |
121 | } else output_width = 80 - sizeof("start-stop-daemon, ") - 8; | 119 | } |
122 | 120 | ||
123 | printf("%s\n" | 121 | printf("%s\n" |
124 | "Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n" | 122 | "Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n" |
@@ -130,19 +128,19 @@ int busybox_main(int argc, char **argv) | |||
130 | "\tlink to busybox for each function they wish to use and BusyBox\n" | 128 | "\tlink to busybox for each function they wish to use and BusyBox\n" |
131 | "\twill act like whatever it was invoked as!\n" | 129 | "\twill act like whatever it was invoked as!\n" |
132 | "\nCurrently defined functions:\n", bb_msg_full_version); | 130 | "\nCurrently defined functions:\n", bb_msg_full_version); |
133 | 131 | col = 0; | |
134 | col=0; | ||
135 | for(a = applets; a->name;) { | 132 | for(a = applets; a->name;) { |
136 | col += printf("%s%s", (col ? ", " : "\t"), (a++)->name); | 133 | col += printf("%s%s", (col ? ", " : "\t"), a->name); |
134 | a++; | ||
137 | if (col > output_width && a->name) { | 135 | if (col > output_width && a->name) { |
138 | printf(",\n"); | 136 | puts(","); |
139 | col = 0; | 137 | col = 0; |
140 | } | 138 | } |
141 | } | 139 | } |
142 | printf("\n\n"); | 140 | puts("\n"); |
143 | exit(0); | 141 | return 0; |
144 | } | 142 | } |
145 | } else run_applet_by_name(argv[1], argc-1, argv+1); | 143 | } else run_applet_by_name(argv[1], argc - 1, argv + 1); |
146 | 144 | ||
147 | bb_error_msg_and_die("applet not found"); | 145 | bb_error_msg_and_die("applet not found"); |
148 | } | 146 | } |