aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 03:11:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 03:11:58 +0000
commitc44ab01b75aba758fe0aff4b34b25d733e370dc2 (patch)
tree7aaff270868ae6e6ff78fb5c42d42f5645a6a67a /shell
parent95cb3263ae8f9afda0f6af3f777739506a0dfc62 (diff)
downloadbusybox-w32-c44ab01b75aba758fe0aff4b34b25d733e370dc2.tar.gz
busybox-w32-c44ab01b75aba758fe0aff4b34b25d733e370dc2.tar.bz2
busybox-w32-c44ab01b75aba758fe0aff4b34b25d733e370dc2.zip
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 950cdaa02..f98fc4178 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6468,43 +6468,6 @@ casematch(union node *pattern, char *val)
6468 6468
6469/* ============ find_command */ 6469/* ============ find_command */
6470 6470
6471#if ENABLE_FEATURE_SH_STANDALONE_SHELL
6472static int
6473is_safe_applet(char *name)
6474{
6475 /* It isn't a bug to have non-existent applet here... */
6476 /* ...just a waste of space... */
6477 static const char safe_applets[][8] = {
6478 "["
6479 USE_AWK (, "awk" )
6480 USE_CAT (, "cat" )
6481 USE_CHMOD (, "chmod" )
6482 USE_CHOWN (, "chown" )
6483 USE_CP (, "cp" )
6484 USE_CUT (, "cut" )
6485 USE_DD (, "dd" )
6486 USE_ECHO (, "echo" )
6487 USE_FIND (, "find" )
6488 USE_HEXDUMP(, "hexdump")
6489 USE_LN (, "ln" )
6490 USE_LS (, "ls" )
6491 USE_MKDIR (, "mkdir" )
6492 USE_RM (, "rm" )
6493 USE_SORT (, "sort" )
6494 USE_TEST (, "test" )
6495 USE_TOUCH (, "touch" )
6496 USE_XARGS (, "xargs" )
6497 };
6498 int n = sizeof(safe_applets) / sizeof(safe_applets[0]);
6499 int i;
6500 for (i = 0; i < n; i++)
6501 if (strcmp(safe_applets[i], name) == 0)
6502 return 1;
6503
6504 return 0;
6505}
6506#endif
6507
6508struct builtincmd { 6471struct builtincmd {
6509 const char *name; 6472 const char *name;
6510 int (*builtin)(int, char **); 6473 int (*builtin)(int, char **);
@@ -6570,17 +6533,15 @@ tryexec(char *cmd, char **argv, char **envp)
6570 6533
6571#if ENABLE_FEATURE_SH_STANDALONE_SHELL 6534#if ENABLE_FEATURE_SH_STANDALONE_SHELL
6572 if (strchr(cmd, '/') == NULL) { 6535 if (strchr(cmd, '/') == NULL) {
6573 struct BB_applet *a; 6536 const struct BB_applet *a;
6574 char **c;
6575 6537
6576 a = find_applet_by_name(cmd); 6538 a = find_applet_by_name(cmd);
6577 if (a) { 6539 if (a) {
6578 if (is_safe_applet(cmd)) { 6540 if (a->noexec) {
6579 c = argv; 6541 char **c = argv;
6580 while (*c) 6542 while (*c) c++;
6581 c++; 6543 current_applet = a;
6582 applet_name = cmd; 6544 run_current_applet_and_exit(c - argv, argv);
6583 exit(a->main(c - argv, argv));
6584 } 6545 }
6585 /* re-exec ourselves with the new arguments */ 6546 /* re-exec ourselves with the new arguments */
6586 execve(CONFIG_BUSYBOX_EXEC_PATH, argv, envp); 6547 execve(CONFIG_BUSYBOX_EXEC_PATH, argv, envp);
@@ -6608,7 +6569,7 @@ tryexec(char *cmd, char **argv, char **envp)
6608 ; 6569 ;
6609 ap = new = ckmalloc((ap - argv + 2) * sizeof(char *)); 6570 ap = new = ckmalloc((ap - argv + 2) * sizeof(char *));
6610 ap[1] = cmd; 6571 ap[1] = cmd;
6611 *ap = cmd = (char *)DEFAULT_SHELL; 6572 ap[0] = cmd = (char *)DEFAULT_SHELL;
6612 ap += 2; 6573 ap += 2;
6613 argv++; 6574 argv++;
6614 while ((*ap++ = *argv++)) 6575 while ((*ap++ = *argv++))
@@ -11161,12 +11122,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
11161 entry->u.index = -1; 11122 entry->u.index = -1;
11162 return; 11123 return;
11163 } 11124 }
11164 /* Already caught above
11165 if (is_safe_applet(name)) {
11166 entry->cmdtype = CMDNORMAL;
11167 entry->u.index = -1;
11168 return;
11169 }*/
11170#endif 11125#endif
11171 11126
11172 updatetbl = (path == pathval()); 11127 updatetbl = (path == pathval());