diff options
author | Ron Yorston <rmy@pobox.com> | 2018-11-01 11:04:47 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-11-01 11:07:26 +0100 |
commit | 151de441e7a19ce3afba0c59b083240a801222cf (patch) | |
tree | ab4574bf623c162848b20d6495d139df23e337fd | |
parent | aa2959c90d9c3217ddb6f482b82fef7234ad9bde (diff) | |
download | busybox-w32-151de441e7a19ce3afba0c59b083240a801222cf.tar.gz busybox-w32-151de441e7a19ce3afba0c59b083240a801222cf.tar.bz2 busybox-w32-151de441e7a19ce3afba0c59b083240a801222cf.zip |
ash: recognize embedded scripts in SH_STANDALONE mode
function old new delta
find_script_by_name - 51 +51
shellexec 254 271 +17
find_command 990 1007 +17
evalcommand 1653 1661 +8
doCommands 2233 2222 -11
run_applet_and_exit 128 100 -28
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/4 up/down: 104/-52) Total: 52 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/appletlib.c | 8 | ||||
-rw-r--r-- | shell/ash.c | 12 |
3 files changed, 17 insertions, 5 deletions
diff --git a/include/libbb.h b/include/libbb.h index affff5874..a32608ebd 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1322,7 +1322,7 @@ void bb_logenv_override(void) FAST_FUNC; | |||
1322 | #endif | 1322 | #endif |
1323 | 1323 | ||
1324 | /* Embedded script support */ | 1324 | /* Embedded script support */ |
1325 | //int find_script_by_name(const char *arg IF_FEATURE_SH_STANDALONE(, int offset)) FAST_FUNC; | 1325 | int find_script_by_name(const char *name) FAST_FUNC; |
1326 | char *get_script_content(unsigned n) FAST_FUNC; | 1326 | char *get_script_content(unsigned n) FAST_FUNC; |
1327 | 1327 | ||
1328 | /* Applets which are useful from another applets */ | 1328 | /* Applets which are useful from another applets */ |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 4e6d1c3d6..92d99fbe8 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -964,20 +964,20 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar | |||
964 | # endif /* NUM_APPLETS > 0 */ | 964 | # endif /* NUM_APPLETS > 0 */ |
965 | 965 | ||
966 | # if NUM_SCRIPTS > 0 | 966 | # if NUM_SCRIPTS > 0 |
967 | static int | 967 | int FAST_FUNC |
968 | find_script_by_name(const char *arg) | 968 | find_script_by_name(const char *name) |
969 | { | 969 | { |
970 | const char *s = script_names; | 970 | const char *s = script_names; |
971 | int i = 0; | 971 | int i = 0; |
972 | 972 | ||
973 | while (*s) { | 973 | while (*s) { |
974 | if (strcmp(arg, s) == 0) | 974 | if (strcmp(name, s) == 0) |
975 | return i; | 975 | return i; |
976 | i++; | 976 | i++; |
977 | while (*s++ != '\0') | 977 | while (*s++ != '\0') |
978 | continue; | 978 | continue; |
979 | } | 979 | } |
980 | return -1; | 980 | return -0x10000; /* make it so that NUM_APPLETS + <error> is still < 0 */ |
981 | } | 981 | } |
982 | 982 | ||
983 | static char * | 983 | static char * |
diff --git a/shell/ash.c b/shell/ash.c index 3adb6d0d2..58ecf6d2c 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -8085,6 +8085,9 @@ static void shellexec(char *prog, char **argv, const char *path, int idx) | |||
8085 | if (strchr(prog, '/') != NULL | 8085 | if (strchr(prog, '/') != NULL |
8086 | #if ENABLE_FEATURE_SH_STANDALONE | 8086 | #if ENABLE_FEATURE_SH_STANDALONE |
8087 | || (applet_no = find_applet_by_name(prog)) >= 0 | 8087 | || (applet_no = find_applet_by_name(prog)) >= 0 |
8088 | # if NUM_SCRIPTS > 0 | ||
8089 | || (applet_no = NUM_APPLETS + find_script_by_name(prog)) >= 0 | ||
8090 | # endif | ||
8088 | #endif | 8091 | #endif |
8089 | ) { | 8092 | ) { |
8090 | tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp); | 8093 | tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp); |
@@ -10186,6 +10189,10 @@ evalcommand(union node *cmd, int flags) | |||
10186 | */ | 10189 | */ |
10187 | /* find_command() encodes applet_no as (-2 - applet_no) */ | 10190 | /* find_command() encodes applet_no as (-2 - applet_no) */ |
10188 | int applet_no = (- cmdentry.u.index - 2); | 10191 | int applet_no = (- cmdentry.u.index - 2); |
10192 | # if NUM_SCRIPTS > 0 | ||
10193 | /* Applets are ok, but not embedded scripts */ | ||
10194 | if (applet_no < NUM_APPLETS) | ||
10195 | # endif | ||
10189 | if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) { | 10196 | if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) { |
10190 | char **sv_environ; | 10197 | char **sv_environ; |
10191 | 10198 | ||
@@ -13368,6 +13375,11 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
13368 | #if ENABLE_FEATURE_SH_STANDALONE | 13375 | #if ENABLE_FEATURE_SH_STANDALONE |
13369 | { | 13376 | { |
13370 | int applet_no = find_applet_by_name(name); | 13377 | int applet_no = find_applet_by_name(name); |
13378 | # if NUM_SCRIPTS > 0 | ||
13379 | if (applet_no < 0) | ||
13380 | /* embedded script indices are offset by NUM_APPLETS */ | ||
13381 | applet_no = NUM_APPLETS + find_script_by_name(name); | ||
13382 | # endif | ||
13371 | if (applet_no >= 0) { | 13383 | if (applet_no >= 0) { |
13372 | entry->cmdtype = CMDNORMAL; | 13384 | entry->cmdtype = CMDNORMAL; |
13373 | entry->u.index = -2 - applet_no; | 13385 | entry->u.index = -2 - applet_no; |