summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko2007-04-09 03:11:58 +0000
committerDenis Vlasenko2007-04-09 03:11:58 +0000
commitc44ab01b75aba758fe0aff4b34b25d733e370dc2 (patch)
tree7aaff270868ae6e6ff78fb5c42d42f5645a6a67a /shell
parent95cb3263ae8f9afda0f6af3f777739506a0dfc62 (diff)
downloadbusybox-c44ab01b75aba758fe0aff4b34b25d733e370dc2.zip
busybox-c44ab01b75aba758fe0aff4b34b25d733e370dc2.tar.gz
Improve STANDALONE_SHELL. "safe" applets are renamed NOEXEC applets
and now this fact is recorded in applets.h, not ash.c. Several fixes to "--help + STANDALONE_SHELL" scenarios. function old new delta run_current_applet_and_exit - 355 +355 arith 2064 2073 +9 refresh 1148 1156 +8 getopt32 1068 1073 +5 telnet_main 1510 1514 +4 md5_sha1_sum_main 565 566 +1 xstrtoul_range_sfx 255 251 -4 packed_usage 22523 22514 -9 tryexec 255 203 -52 static.safe_applets 152 - -152 .rodata 131320 131128 -192 run_applet_by_name 869 506 -363 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 5/5 up/down: 382/-772) Total: -390 bytes ./busybox ash -c 'i=20000; while test $i != 0; do touch z; i=$((i-1)); done' runs more than twice as fast with STANDALONE_SHELL versus without.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c59
1 files changed, 7 insertions, 52 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 950cdaa..f98fc41 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6468,43 +6468,6 @@ casematch(union node *pattern, char *val)
/* ============ find_command */
-#if ENABLE_FEATURE_SH_STANDALONE_SHELL
-static int
-is_safe_applet(char *name)
-{
- /* It isn't a bug to have non-existent applet here... */
- /* ...just a waste of space... */
- static const char safe_applets[][8] = {
- "["
- USE_AWK (, "awk" )
- USE_CAT (, "cat" )
- USE_CHMOD (, "chmod" )
- USE_CHOWN (, "chown" )
- USE_CP (, "cp" )
- USE_CUT (, "cut" )
- USE_DD (, "dd" )
- USE_ECHO (, "echo" )
- USE_FIND (, "find" )
- USE_HEXDUMP(, "hexdump")
- USE_LN (, "ln" )
- USE_LS (, "ls" )
- USE_MKDIR (, "mkdir" )
- USE_RM (, "rm" )
- USE_SORT (, "sort" )
- USE_TEST (, "test" )
- USE_TOUCH (, "touch" )
- USE_XARGS (, "xargs" )
- };
- int n = sizeof(safe_applets) / sizeof(safe_applets[0]);
- int i;
- for (i = 0; i < n; i++)
- if (strcmp(safe_applets[i], name) == 0)
- return 1;
-
- return 0;
-}
-#endif
-
struct builtincmd {
const char *name;
int (*builtin)(int, char **);
@@ -6570,17 +6533,15 @@ tryexec(char *cmd, char **argv, char **envp)
#if ENABLE_FEATURE_SH_STANDALONE_SHELL
if (strchr(cmd, '/') == NULL) {
- struct BB_applet *a;
- char **c;
+ const struct BB_applet *a;
a = find_applet_by_name(cmd);
if (a) {
- if (is_safe_applet(cmd)) {
- c = argv;
- while (*c)
- c++;
- applet_name = cmd;
- exit(a->main(c - argv, argv));
+ if (a->noexec) {
+ char **c = argv;
+ while (*c) c++;
+ current_applet = a;
+ run_current_applet_and_exit(c - argv, argv);
}
/* re-exec ourselves with the new arguments */
execve(CONFIG_BUSYBOX_EXEC_PATH, argv, envp);
@@ -6608,7 +6569,7 @@ tryexec(char *cmd, char **argv, char **envp)
;
ap = new = ckmalloc((ap - argv + 2) * sizeof(char *));
ap[1] = cmd;
- *ap = cmd = (char *)DEFAULT_SHELL;
+ ap[0] = cmd = (char *)DEFAULT_SHELL;
ap += 2;
argv++;
while ((*ap++ = *argv++))
@@ -11161,12 +11122,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
entry->u.index = -1;
return;
}
- /* Already caught above
- if (is_safe_applet(name)) {
- entry->cmdtype = CMDNORMAL;
- entry->u.index = -1;
- return;
- }*/
#endif
updatetbl = (path == pathval());