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-1aa7e477b1b727db77cac2d717f0fcca40587f78.tar.gz |
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 @@ #if DEBUG #define _GNU_SOURCE #endif -#include "busybox.h" /* for struct bb_applet */ +#include "busybox.h" /* for applet_names */ #include <paths.h> #include <setjmp.h> #include <fnmatch.h> @@ -6479,12 +6479,10 @@ tryexec(char *cmd, char **argv, char **envp) #if ENABLE_FEATURE_SH_STANDALONE if (strchr(cmd, '/') == NULL) { - const struct bb_applet *a; - - a = find_applet_by_name(cmd); - if (a) { - if (a->noexec) - run_appletstruct_and_exit(a, argv); + int a = find_applet_by_name(cmd); + if (a >= 0) { + if (APPLET_IS_NOEXEC(a)) + run_applet_no_and_exit(a, argv); /* re-exec ourselves with the new arguments */ execve(bb_busybox_exec_path, argv, envp); /* If they called chroot or otherwise made the binary no longer @@ -6539,7 +6537,7 @@ shellexec(char **argv, const char *path, int idx) envp = environment(); if (strchr(argv[0], '/') #if ENABLE_FEATURE_SH_STANDALONE - || find_applet_by_name(argv[0]) + || find_applet_by_name(argv[0]) >= 0 #endif ) { tryexec(argv[0], argv, envp); @@ -11117,7 +11115,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) } #if ENABLE_FEATURE_SH_STANDALONE - if (find_applet_by_name(name)) { + if (find_applet_by_name(name) >= 0) { entry->cmdtype = CMDNORMAL; entry->u.index = -1; return; @@ -11298,11 +11296,15 @@ helpcmd(int argc, char **argv) } } #if ENABLE_FEATURE_SH_STANDALONE - for (i = 0; i < NUM_APPLETS; i++) { - col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), applets[i].name); - if (col > 60) { - out1fmt("\n"); - col = 0; + { + const char *a = applet_names; + while (*a) { + col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), a); + if (col > 60) { + out1fmt("\n"); + col = 0; + } + a += strlen(a) + 1; } } #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 @@ extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */ -#include "busybox.h" /* for struct bb_applet */ +#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ #if !BB_MMU @@ -1464,12 +1464,12 @@ static void pseudo_exec_argv(char **argv) /* Check if the command matches any busybox applets */ #if ENABLE_FEATURE_SH_STANDALONE if (strchr(argv[0], '/') == NULL) { - const struct bb_applet *a = find_applet_by_name(argv[0]); - if (a) { - if (a->noexec) { + int a = find_applet_by_name(argv[0]); + if (a >= 0) { + if (APPLET_IS_NOEXEC(a)) { debug_printf_exec("running applet '%s'\n", argv[0]); -// is it ok that run_appletstruct_and_exit() does exit(), not _exit()? - run_appletstruct_and_exit(a, argv); +// is it ok that run_applet_no_and_exit() does exit(), not _exit()? + run_applet_no_and_exit(a, argv); } /* re-exec ourselves with the new arguments */ debug_printf_exec("re-execing applet '%s'\n", argv[0]); @@ -1855,8 +1855,8 @@ static int run_pipe_real(struct pipe *pi) } #if ENABLE_FEATURE_SH_STANDALONE { - const struct bb_applet *a = find_applet_by_name(argv[i]); - if (a && a->nofork) { + int a = find_applet_by_name(argv[i]); + if (a >= 0 && APPLET_IS_NOFORK(a)) { setup_redirects(child, squirrel); save_nofork_data(&nofork_save); 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 @@ #include <getopt.h> #include <glob.h> -#include "busybox.h" /* for struct bb_applet */ +#include "libbb.h" #define expand_t glob_t @@ -1253,8 +1253,8 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2]) } #if ENABLE_FEATURE_SH_STANDALONE { - const struct bb_applet *a = find_applet_by_name(child->argv[i]); - if (a && a->nofork) { + int a = find_applet_by_name(child->argv[i]); + if (a >= 0 && APPLET_IS_NOFORK(a)) { setup_redirects(child, squirrel); rcode = run_nofork_applet(a, child->argv + i); 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 @@ # define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) # define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1]) # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) -static char *find_applet_by_name(const char *applet) +static int find_applet_by_name(const char *applet) { - return NULL; + return -1; } static char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) { @@ -83,7 +83,7 @@ static char *itoa(int n) return local_buf; } #else -# include "busybox.h" +# include "busybox.h" /* for applet_names */ extern char **environ; #endif @@ -3057,7 +3057,7 @@ static const char *rexecve(char *c, char **v, char **envp) char *name = c; if (ENABLE_FEATURE_SH_STANDALONE) { - if (find_applet_by_name(name)) { + if (find_applet_by_name(name) >= 0) { /* We have to exec here since we vforked. Running * run_applet_and_exit() won't work and bad things * will happen. */ @@ -3188,15 +3188,15 @@ static int dohelp(struct op *t) } #if ENABLE_FEATURE_SH_STANDALONE { - const struct bb_applet *applet = applets; + const char *applet = applet_names; - while (applet->name) { - col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet->name); + while (*applet) { + col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet); if (col > 60) { bb_putchar('\n'); col = 0; } - applet++; + applet += strlen(applet) + 1; } } #endif |