diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-31 05:27:09 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-31 05:27:09 +0200 |
commit | 75481d363454a3e0640a5bd0f78d2cc4403e6235 (patch) | |
tree | a003f48db7a7ecc12736a0ec3c711424f7d64a6d /shell | |
parent | bf1c344dfdc6f38ad6aa81c10b7b050e0dfc5d96 (diff) | |
download | busybox-w32-75481d363454a3e0640a5bd0f78d2cc4403e6235.tar.gz busybox-w32-75481d363454a3e0640a5bd0f78d2cc4403e6235.tar.bz2 busybox-w32-75481d363454a3e0640a5bd0f78d2cc4403e6235.zip |
hush: functions have priority over builtins (!)
function old new delta
pseudo_exec_argv 291 305 +14
run_pipe 1560 1555 -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-5) Total: 9 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash_test/ash-misc/func_prio_over_builtins.right | 5 | ||||
-rwxr-xr-x | shell/ash_test/ash-misc/func_prio_over_builtins.tests | 5 | ||||
-rw-r--r-- | shell/hush.c | 33 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/func_prio_over_builtins.right | 5 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/func_prio_over_builtins.tests | 5 |
5 files changed, 39 insertions, 14 deletions
diff --git a/shell/ash_test/ash-misc/func_prio_over_builtins.right b/shell/ash_test/ash-misc/func_prio_over_builtins.right new file mode 100644 index 000000000..54e56dff4 --- /dev/null +++ b/shell/ash_test/ash-misc/func_prio_over_builtins.right | |||
@@ -0,0 +1,5 @@ | |||
1 | YES | ||
2 | YES | ||
3 | YES | ||
4 | YES | ||
5 | Ok:YES | ||
diff --git a/shell/ash_test/ash-misc/func_prio_over_builtins.tests b/shell/ash_test/ash-misc/func_prio_over_builtins.tests new file mode 100755 index 000000000..4f71bfda0 --- /dev/null +++ b/shell/ash_test/ash-misc/func_prio_over_builtins.tests | |||
@@ -0,0 +1,5 @@ | |||
1 | true() { echo YES >&2; } | ||
2 | true | ||
3 | true | true | ||
4 | (true) | ||
5 | echo Ok:`true 2>&1` | ||
diff --git a/shell/hush.c b/shell/hush.c index 8e9e0e9e8..2fba637ae 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -7090,11 +7090,13 @@ static void exec_function(char ***to_free, | |||
7090 | argv[0] = G.global_argv[0]; | 7090 | argv[0] = G.global_argv[0]; |
7091 | G.global_argv = argv; | 7091 | G.global_argv = argv; |
7092 | G.global_argc = n = 1 + string_array_len(argv + 1); | 7092 | G.global_argc = n = 1 + string_array_len(argv + 1); |
7093 | //? close_saved_fds_and_FILE_list(); | ||
7093 | /* On MMU, funcp->body is always non-NULL */ | 7094 | /* On MMU, funcp->body is always non-NULL */ |
7094 | n = run_list(funcp->body); | 7095 | n = run_list(funcp->body); |
7095 | fflush_all(); | 7096 | fflush_all(); |
7096 | _exit(n); | 7097 | _exit(n); |
7097 | # else | 7098 | # else |
7099 | //? close_saved_fds_and_FILE_list(); | ||
7098 | re_execute_shell(to_free, | 7100 | re_execute_shell(to_free, |
7099 | funcp->body_as_string, | 7101 | funcp->body_as_string, |
7100 | G.global_argv[0], | 7102 | G.global_argv[0], |
@@ -7180,6 +7182,7 @@ static void exec_builtin(char ***to_free, | |||
7180 | #if BB_MMU | 7182 | #if BB_MMU |
7181 | int rcode; | 7183 | int rcode; |
7182 | fflush_all(); | 7184 | fflush_all(); |
7185 | //? close_saved_fds_and_FILE_list(); | ||
7183 | rcode = x->b_function(argv); | 7186 | rcode = x->b_function(argv); |
7184 | fflush_all(); | 7187 | fflush_all(); |
7185 | _exit(rcode); | 7188 | _exit(rcode); |
@@ -7301,6 +7304,16 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
7301 | goto skip; | 7304 | goto skip; |
7302 | #endif | 7305 | #endif |
7303 | 7306 | ||
7307 | #if ENABLE_HUSH_FUNCTIONS | ||
7308 | /* Check if the command matches any functions (this goes before bltins) */ | ||
7309 | { | ||
7310 | const struct function *funcp = find_function(argv[0]); | ||
7311 | if (funcp) { | ||
7312 | exec_function(&nommu_save->argv_from_re_execing, funcp, argv); | ||
7313 | } | ||
7314 | } | ||
7315 | #endif | ||
7316 | |||
7304 | /* Check if the command matches any of the builtins. | 7317 | /* Check if the command matches any of the builtins. |
7305 | * Depending on context, this might be redundant. But it's | 7318 | * Depending on context, this might be redundant. But it's |
7306 | * easier to waste a few CPU cycles than it is to figure out | 7319 | * easier to waste a few CPU cycles than it is to figure out |
@@ -7317,15 +7330,6 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
7317 | exec_builtin(&nommu_save->argv_from_re_execing, x, argv); | 7330 | exec_builtin(&nommu_save->argv_from_re_execing, x, argv); |
7318 | } | 7331 | } |
7319 | } | 7332 | } |
7320 | #if ENABLE_HUSH_FUNCTIONS | ||
7321 | /* Check if the command matches any functions */ | ||
7322 | { | ||
7323 | const struct function *funcp = find_function(argv[0]); | ||
7324 | if (funcp) { | ||
7325 | exec_function(&nommu_save->argv_from_re_execing, funcp, argv); | ||
7326 | } | ||
7327 | } | ||
7328 | #endif | ||
7329 | 7333 | ||
7330 | #if ENABLE_FEATURE_SH_STANDALONE | 7334 | #if ENABLE_FEATURE_SH_STANDALONE |
7331 | /* Check if the command matches any busybox applets */ | 7335 | /* Check if the command matches any busybox applets */ |
@@ -7339,7 +7343,7 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
7339 | * should not show tty fd open. | 7343 | * should not show tty fd open. |
7340 | */ | 7344 | */ |
7341 | close_saved_fds_and_FILE_list(); | 7345 | close_saved_fds_and_FILE_list(); |
7342 | ///FIXME: should also close saved redir fds | 7346 | //FIXME: should also close saved redir fds |
7343 | debug_printf_exec("running applet '%s'\n", argv[0]); | 7347 | debug_printf_exec("running applet '%s'\n", argv[0]); |
7344 | run_applet_no_and_exit(a, argv[0], argv); | 7348 | run_applet_no_and_exit(a, argv[0], argv); |
7345 | } | 7349 | } |
@@ -7976,12 +7980,13 @@ static NOINLINE int run_pipe(struct pipe *pi) | |||
7976 | return G.last_exitcode; | 7980 | return G.last_exitcode; |
7977 | } | 7981 | } |
7978 | 7982 | ||
7979 | x = find_builtin(argv_expanded[0]); | ||
7980 | #if ENABLE_HUSH_FUNCTIONS | 7983 | #if ENABLE_HUSH_FUNCTIONS |
7981 | funcp = NULL; | 7984 | /* Check if argv[0] matches any functions (this goes before bltins) */ |
7982 | if (!x) | 7985 | funcp = find_function(argv_expanded[0]); |
7983 | funcp = find_function(argv_expanded[0]); | ||
7984 | #endif | 7986 | #endif |
7987 | x = NULL; | ||
7988 | if (!funcp) | ||
7989 | x = find_builtin(argv_expanded[0]); | ||
7985 | if (x || funcp) { | 7990 | if (x || funcp) { |
7986 | if (!funcp) { | 7991 | if (!funcp) { |
7987 | if (x->b_function == builtin_exec && argv_expanded[1] == NULL) { | 7992 | if (x->b_function == builtin_exec && argv_expanded[1] == NULL) { |
diff --git a/shell/hush_test/hush-misc/func_prio_over_builtins.right b/shell/hush_test/hush-misc/func_prio_over_builtins.right new file mode 100644 index 000000000..54e56dff4 --- /dev/null +++ b/shell/hush_test/hush-misc/func_prio_over_builtins.right | |||
@@ -0,0 +1,5 @@ | |||
1 | YES | ||
2 | YES | ||
3 | YES | ||
4 | YES | ||
5 | Ok:YES | ||
diff --git a/shell/hush_test/hush-misc/func_prio_over_builtins.tests b/shell/hush_test/hush-misc/func_prio_over_builtins.tests new file mode 100755 index 000000000..4f71bfda0 --- /dev/null +++ b/shell/hush_test/hush-misc/func_prio_over_builtins.tests | |||
@@ -0,0 +1,5 @@ | |||
1 | true() { echo YES >&2; } | ||
2 | true | ||
3 | true | true | ||
4 | (true) | ||
5 | echo Ok:`true 2>&1` | ||