diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-28 06:49:03 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-28 06:49:03 +0000 |
commit | 1aa7e477b1b727db77cac2d717f0fcca40587f78 (patch) | |
tree | 247171517f0e01d32a71a5e96f4bef462cc0e9c6 /shell | |
parent | 79c6904faff1ebd4bf4b7d9cd0c20ca70f4cec75 (diff) | |
download | busybox-w32-1aa7e477b1b727db77cac2d717f0fcca40587f78.tar.gz busybox-w32-1aa7e477b1b727db77cac2d717f0fcca40587f78.tar.bz2 busybox-w32-1aa7e477b1b727db77cac2d717f0fcca40587f78.zip |
reorganize applet table. Eliminates pointers to names.
Should be a big win for libbusybox. busybox wins too:
text data bss dec hex filename
776524 929 9100 786553 c0079 busybox_old
775903 929 9100 785932 bfe0c busybox_unstripped
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 30 | ||||
-rw-r--r-- | shell/hush.c | 16 | ||||
-rw-r--r-- | shell/lash_unused.c | 6 | ||||
-rw-r--r-- | shell/msh.c | 16 |
4 files changed, 35 insertions, 33 deletions
diff --git a/shell/ash.c b/shell/ash.c index 8f388f59b..9b9fe5b6d 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -53,7 +53,7 @@ | |||
53 | #if DEBUG | 53 | #if DEBUG |
54 | #define _GNU_SOURCE | 54 | #define _GNU_SOURCE |
55 | #endif | 55 | #endif |
56 | #include "busybox.h" /* for struct bb_applet */ | 56 | #include "busybox.h" /* for applet_names */ |
57 | #include <paths.h> | 57 | #include <paths.h> |
58 | #include <setjmp.h> | 58 | #include <setjmp.h> |
59 | #include <fnmatch.h> | 59 | #include <fnmatch.h> |
@@ -6479,12 +6479,10 @@ tryexec(char *cmd, char **argv, char **envp) | |||
6479 | 6479 | ||
6480 | #if ENABLE_FEATURE_SH_STANDALONE | 6480 | #if ENABLE_FEATURE_SH_STANDALONE |
6481 | if (strchr(cmd, '/') == NULL) { | 6481 | if (strchr(cmd, '/') == NULL) { |
6482 | const struct bb_applet *a; | 6482 | int a = find_applet_by_name(cmd); |
6483 | 6483 | if (a >= 0) { | |
6484 | a = find_applet_by_name(cmd); | 6484 | if (APPLET_IS_NOEXEC(a)) |
6485 | if (a) { | 6485 | run_applet_no_and_exit(a, argv); |
6486 | if (a->noexec) | ||
6487 | run_appletstruct_and_exit(a, argv); | ||
6488 | /* re-exec ourselves with the new arguments */ | 6486 | /* re-exec ourselves with the new arguments */ |
6489 | execve(bb_busybox_exec_path, argv, envp); | 6487 | execve(bb_busybox_exec_path, argv, envp); |
6490 | /* If they called chroot or otherwise made the binary no longer | 6488 | /* If they called chroot or otherwise made the binary no longer |
@@ -6539,7 +6537,7 @@ shellexec(char **argv, const char *path, int idx) | |||
6539 | envp = environment(); | 6537 | envp = environment(); |
6540 | if (strchr(argv[0], '/') | 6538 | if (strchr(argv[0], '/') |
6541 | #if ENABLE_FEATURE_SH_STANDALONE | 6539 | #if ENABLE_FEATURE_SH_STANDALONE |
6542 | || find_applet_by_name(argv[0]) | 6540 | || find_applet_by_name(argv[0]) >= 0 |
6543 | #endif | 6541 | #endif |
6544 | ) { | 6542 | ) { |
6545 | tryexec(argv[0], argv, envp); | 6543 | tryexec(argv[0], argv, envp); |
@@ -11117,7 +11115,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
11117 | } | 11115 | } |
11118 | 11116 | ||
11119 | #if ENABLE_FEATURE_SH_STANDALONE | 11117 | #if ENABLE_FEATURE_SH_STANDALONE |
11120 | if (find_applet_by_name(name)) { | 11118 | if (find_applet_by_name(name) >= 0) { |
11121 | entry->cmdtype = CMDNORMAL; | 11119 | entry->cmdtype = CMDNORMAL; |
11122 | entry->u.index = -1; | 11120 | entry->u.index = -1; |
11123 | return; | 11121 | return; |
@@ -11298,11 +11296,15 @@ helpcmd(int argc, char **argv) | |||
11298 | } | 11296 | } |
11299 | } | 11297 | } |
11300 | #if ENABLE_FEATURE_SH_STANDALONE | 11298 | #if ENABLE_FEATURE_SH_STANDALONE |
11301 | for (i = 0; i < NUM_APPLETS; i++) { | 11299 | { |
11302 | col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name); | 11300 | const char *a = applet_names; |
11303 | if (col > 60) { | 11301 | while (*a) { |
11304 | out1fmt("\n"); | 11302 | col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), a); |
11305 | col = 0; | 11303 | if (col > 60) { |
11304 | out1fmt("\n"); | ||
11305 | col = 0; | ||
11306 | } | ||
11307 | a += strlen(a) + 1; | ||
11306 | } | 11308 | } |
11307 | } | 11309 | } |
11308 | #endif | 11310 | #endif |
diff --git a/shell/hush.c b/shell/hush.c index f7e2a4a14..8e42a8f3f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -83,7 +83,7 @@ | |||
83 | 83 | ||
84 | extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */ | 84 | extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */ |
85 | 85 | ||
86 | #include "busybox.h" /* for struct bb_applet */ | 86 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ |
87 | 87 | ||
88 | 88 | ||
89 | #if !BB_MMU | 89 | #if !BB_MMU |
@@ -1464,12 +1464,12 @@ static void pseudo_exec_argv(char **argv) | |||
1464 | /* Check if the command matches any busybox applets */ | 1464 | /* Check if the command matches any busybox applets */ |
1465 | #if ENABLE_FEATURE_SH_STANDALONE | 1465 | #if ENABLE_FEATURE_SH_STANDALONE |
1466 | if (strchr(argv[0], '/') == NULL) { | 1466 | if (strchr(argv[0], '/') == NULL) { |
1467 | const struct bb_applet *a = find_applet_by_name(argv[0]); | 1467 | int a = find_applet_by_name(argv[0]); |
1468 | if (a) { | 1468 | if (a >= 0) { |
1469 | if (a->noexec) { | 1469 | if (APPLET_IS_NOEXEC(a)) { |
1470 | debug_printf_exec("running applet '%s'\n", argv[0]); | 1470 | debug_printf_exec("running applet '%s'\n", argv[0]); |
1471 | // is it ok that run_appletstruct_and_exit() does exit(), not _exit()? | 1471 | // is it ok that run_applet_no_and_exit() does exit(), not _exit()? |
1472 | run_appletstruct_and_exit(a, argv); | 1472 | run_applet_no_and_exit(a, argv); |
1473 | } | 1473 | } |
1474 | /* re-exec ourselves with the new arguments */ | 1474 | /* re-exec ourselves with the new arguments */ |
1475 | debug_printf_exec("re-execing applet '%s'\n", argv[0]); | 1475 | debug_printf_exec("re-execing applet '%s'\n", argv[0]); |
@@ -1855,8 +1855,8 @@ static int run_pipe_real(struct pipe *pi) | |||
1855 | } | 1855 | } |
1856 | #if ENABLE_FEATURE_SH_STANDALONE | 1856 | #if ENABLE_FEATURE_SH_STANDALONE |
1857 | { | 1857 | { |
1858 | const struct bb_applet *a = find_applet_by_name(argv[i]); | 1858 | int a = find_applet_by_name(argv[i]); |
1859 | if (a && a->nofork) { | 1859 | if (a >= 0 && APPLET_IS_NOFORK(a)) { |
1860 | setup_redirects(child, squirrel); | 1860 | setup_redirects(child, squirrel); |
1861 | save_nofork_data(&nofork_save); | 1861 | save_nofork_data(&nofork_save); |
1862 | argv_expanded = argv + i; | 1862 | argv_expanded = argv + i; |
diff --git a/shell/lash_unused.c b/shell/lash_unused.c index 781dfdb5a..10a9120e2 100644 --- a/shell/lash_unused.c +++ b/shell/lash_unused.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include <getopt.h> | 23 | #include <getopt.h> |
24 | #include <glob.h> | 24 | #include <glob.h> |
25 | 25 | ||
26 | #include "busybox.h" /* for struct bb_applet */ | 26 | #include "libbb.h" |
27 | 27 | ||
28 | #define expand_t glob_t | 28 | #define expand_t glob_t |
29 | 29 | ||
@@ -1253,8 +1253,8 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2]) | |||
1253 | } | 1253 | } |
1254 | #if ENABLE_FEATURE_SH_STANDALONE | 1254 | #if ENABLE_FEATURE_SH_STANDALONE |
1255 | { | 1255 | { |
1256 | const struct bb_applet *a = find_applet_by_name(child->argv[i]); | 1256 | int a = find_applet_by_name(child->argv[i]); |
1257 | if (a && a->nofork) { | 1257 | if (a >= 0 && APPLET_IS_NOFORK(a)) { |
1258 | setup_redirects(child, squirrel); | 1258 | setup_redirects(child, squirrel); |
1259 | rcode = run_nofork_applet(a, child->argv + i); | 1259 | rcode = run_nofork_applet(a, child->argv + i); |
1260 | restore_redirects(squirrel); | 1260 | restore_redirects(squirrel); |
diff --git a/shell/msh.c b/shell/msh.c index 7efd7f96e..32953f4ed 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -45,9 +45,9 @@ | |||
45 | # define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) | 45 | # define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) |
46 | # define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1]) | 46 | # define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1]) |
47 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | 47 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) |
48 | static char *find_applet_by_name(const char *applet) | 48 | static int find_applet_by_name(const char *applet) |
49 | { | 49 | { |
50 | return NULL; | 50 | return -1; |
51 | } | 51 | } |
52 | static char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) | 52 | static char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) |
53 | { | 53 | { |
@@ -83,7 +83,7 @@ static char *itoa(int n) | |||
83 | return local_buf; | 83 | return local_buf; |
84 | } | 84 | } |
85 | #else | 85 | #else |
86 | # include "busybox.h" | 86 | # include "busybox.h" /* for applet_names */ |
87 | extern char **environ; | 87 | extern char **environ; |
88 | #endif | 88 | #endif |
89 | 89 | ||
@@ -3057,7 +3057,7 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
3057 | char *name = c; | 3057 | char *name = c; |
3058 | 3058 | ||
3059 | if (ENABLE_FEATURE_SH_STANDALONE) { | 3059 | if (ENABLE_FEATURE_SH_STANDALONE) { |
3060 | if (find_applet_by_name(name)) { | 3060 | if (find_applet_by_name(name) >= 0) { |
3061 | /* We have to exec here since we vforked. Running | 3061 | /* We have to exec here since we vforked. Running |
3062 | * run_applet_and_exit() won't work and bad things | 3062 | * run_applet_and_exit() won't work and bad things |
3063 | * will happen. */ | 3063 | * will happen. */ |
@@ -3188,15 +3188,15 @@ static int dohelp(struct op *t) | |||
3188 | } | 3188 | } |
3189 | #if ENABLE_FEATURE_SH_STANDALONE | 3189 | #if ENABLE_FEATURE_SH_STANDALONE |
3190 | { | 3190 | { |
3191 | const struct bb_applet *applet = applets; | 3191 | const char *applet = applet_names; |
3192 | 3192 | ||
3193 | while (applet->name) { | 3193 | while (*applet) { |
3194 | col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet->name); | 3194 | col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet); |
3195 | if (col > 60) { | 3195 | if (col > 60) { |
3196 | bb_putchar('\n'); | 3196 | bb_putchar('\n'); |
3197 | col = 0; | 3197 | col = 0; |
3198 | } | 3198 | } |
3199 | applet++; | 3199 | applet += strlen(applet) + 1; |
3200 | } | 3200 | } |
3201 | } | 3201 | } |
3202 | #endif | 3202 | #endif |