diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-16 02:00:03 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-16 02:00:03 +0100 |
commit | 00243b0a1aa7149660e52e748b82a14e5e818150 (patch) | |
tree | 88d21a71c53f4d1ee2fc43612adb3879118b4e42 | |
parent | a7ccdeef396700d1ed78b9f97de0d10c706b169f (diff) | |
download | busybox-w32-00243b0a1aa7149660e52e748b82a14e5e818150.tar.gz busybox-w32-00243b0a1aa7149660e52e748b82a14e5e818150.tar.bz2 busybox-w32-00243b0a1aa7149660e52e748b82a14e5e818150.zip |
hush: fix exit code propagation from `cmd`. +45 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 15 | ||||
-rw-r--r-- | shell/hush_test/hush-psubst/emptytick.right | 8 | ||||
-rwxr-xr-x | shell/hush_test/hush-psubst/emptytick.tests | 4 |
3 files changed, 17 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c index ede8d680e..6dd6a0d03 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -3904,7 +3904,7 @@ static NOINLINE int run_pipe(struct pipe *pi) | |||
3904 | /* if someone gives us an empty string: `cmd with empty output` */ | 3904 | /* if someone gives us an empty string: `cmd with empty output` */ |
3905 | if (!argv_expanded[0]) { | 3905 | if (!argv_expanded[0]) { |
3906 | debug_leave(); | 3906 | debug_leave(); |
3907 | return 0; // or G.last_exitcode? see emptytick.tests | 3907 | return G.last_exitcode; |
3908 | } | 3908 | } |
3909 | 3909 | ||
3910 | x = find_builtin(argv_expanded[0]); | 3910 | x = find_builtin(argv_expanded[0]); |
@@ -6380,15 +6380,26 @@ static struct pipe *parse_stream(char **pstring, | |||
6380 | */ | 6380 | */ |
6381 | static void parse_and_run_stream(struct in_str *inp, int end_trigger) | 6381 | static void parse_and_run_stream(struct in_str *inp, int end_trigger) |
6382 | { | 6382 | { |
6383 | /* Why we need empty flag? | ||
6384 | * An obscure corner case "false; ``; echo $?": | ||
6385 | * empty command in `` should still set $? to 0. | ||
6386 | * But we can't just set $? to 0 at the start, | ||
6387 | * this breaks "false; echo `echo $?`" case. | ||
6388 | */ | ||
6389 | bool empty = 1; | ||
6383 | while (1) { | 6390 | while (1) { |
6384 | struct pipe *pipe_list; | 6391 | struct pipe *pipe_list; |
6385 | 6392 | ||
6386 | pipe_list = parse_stream(NULL, inp, end_trigger); | 6393 | pipe_list = parse_stream(NULL, inp, end_trigger); |
6387 | if (!pipe_list) /* EOF */ | 6394 | if (!pipe_list) { /* EOF */ |
6395 | if (empty) | ||
6396 | G.last_exitcode = 0; | ||
6388 | break; | 6397 | break; |
6398 | } | ||
6389 | debug_print_tree(pipe_list, 0); | 6399 | debug_print_tree(pipe_list, 0); |
6390 | debug_printf_exec("parse_and_run_stream: run_and_free_list\n"); | 6400 | debug_printf_exec("parse_and_run_stream: run_and_free_list\n"); |
6391 | run_and_free_list(pipe_list); | 6401 | run_and_free_list(pipe_list); |
6402 | empty = 0; | ||
6392 | } | 6403 | } |
6393 | } | 6404 | } |
6394 | 6405 | ||
diff --git a/shell/hush_test/hush-psubst/emptytick.right b/shell/hush_test/hush-psubst/emptytick.right index 1f60ecfda..2500caba5 100644 --- a/shell/hush_test/hush-psubst/emptytick.right +++ b/shell/hush_test/hush-psubst/emptytick.right | |||
@@ -1,17 +1,17 @@ | |||
1 | 0 | 1 | 0 |
2 | 0 | 2 | 0 |
3 | hush: can't execute '': No such file or directory | 3 | hush: can't execute '': No such file or directory |
4 | 0 | 4 | 127 |
5 | hush: can't execute '': No such file or directory | 5 | hush: can't execute '': No such file or directory |
6 | 0 | 6 | 127 |
7 | 0 | 7 | 0 |
8 | 0 | 8 | 0 |
9 | 0 | 9 | 0 |
10 | 0 | 10 | 0 |
11 | hush: can't execute '': No such file or directory | 11 | hush: can't execute '': No such file or directory |
12 | 0 | 12 | 127 |
13 | hush: can't execute '': No such file or directory | 13 | hush: can't execute '': No such file or directory |
14 | 0 | 14 | 127 |
15 | 0 | 15 | 0 |
16 | 0 | 16 | 0 |
17 | hush: can't execute '': No such file or directory | 17 | hush: can't execute '': No such file or directory |
diff --git a/shell/hush_test/hush-psubst/emptytick.tests b/shell/hush_test/hush-psubst/emptytick.tests index a269f025a..eaffafb22 100755 --- a/shell/hush_test/hush-psubst/emptytick.tests +++ b/shell/hush_test/hush-psubst/emptytick.tests | |||
@@ -1,17 +1,13 @@ | |||
1 | true; ``; echo $? | 1 | true; ``; echo $? |
2 | false; ``; echo $? | 2 | false; ``; echo $? |
3 | # UNFIXED BUG. bash sets $? to 127: | ||
4 | true; `""`; echo $? | 3 | true; `""`; echo $? |
5 | # bash sets $? to 127: | ||
6 | false; `""`; echo $? | 4 | false; `""`; echo $? |
7 | true; ` `; echo $? | 5 | true; ` `; echo $? |
8 | false; ` `; echo $? | 6 | false; ` `; echo $? |
9 | 7 | ||
10 | true; $(); echo $? | 8 | true; $(); echo $? |
11 | false; $(); echo $? | 9 | false; $(); echo $? |
12 | # bash sets $? to 127: | ||
13 | true; $(""); echo $? | 10 | true; $(""); echo $? |
14 | # bash sets $? to 127: | ||
15 | false; $(""); echo $? | 11 | false; $(""); echo $? |
16 | true; $( ); echo $? | 12 | true; $( ); echo $? |
17 | false; $( ); echo $? | 13 | false; $( ); echo $? |