summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2009-11-16 02:00:03 +0100
committerDenys Vlasenko2009-11-16 02:00:03 +0100
commit00243b0a1aa7149660e52e748b82a14e5e818150 (patch)
tree88d21a71c53f4d1ee2fc43612adb3879118b4e42
parenta7ccdeef396700d1ed78b9f97de0d10c706b169f (diff)
downloadbusybox-00243b0a1aa7149660e52e748b82a14e5e818150.zip
busybox-00243b0a1aa7149660e52e748b82a14e5e818150.tar.gz
hush: fix exit code propagation from `cmd`. +45 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c15
-rw-r--r--shell/hush_test/hush-psubst/emptytick.right8
-rwxr-xr-xshell/hush_test/hush-psubst/emptytick.tests4
3 files changed, 17 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c
index ede8d68..6dd6a0d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3904,7 +3904,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
/* if someone gives us an empty string: `cmd with empty output` */
if (!argv_expanded[0]) {
debug_leave();
- return 0; // or G.last_exitcode? see emptytick.tests
+ return G.last_exitcode;
}
x = find_builtin(argv_expanded[0]);
@@ -6380,15 +6380,26 @@ static struct pipe *parse_stream(char **pstring,
*/
static void parse_and_run_stream(struct in_str *inp, int end_trigger)
{
+ /* Why we need empty flag?
+ * An obscure corner case "false; ``; echo $?":
+ * empty command in `` should still set $? to 0.
+ * But we can't just set $? to 0 at the start,
+ * this breaks "false; echo `echo $?`" case.
+ */
+ bool empty = 1;
while (1) {
struct pipe *pipe_list;
pipe_list = parse_stream(NULL, inp, end_trigger);
- if (!pipe_list) /* EOF */
+ if (!pipe_list) { /* EOF */
+ if (empty)
+ G.last_exitcode = 0;
break;
+ }
debug_print_tree(pipe_list, 0);
debug_printf_exec("parse_and_run_stream: run_and_free_list\n");
run_and_free_list(pipe_list);
+ empty = 0;
}
}
diff --git a/shell/hush_test/hush-psubst/emptytick.right b/shell/hush_test/hush-psubst/emptytick.right
index 1f60ecf..2500cab 100644
--- a/shell/hush_test/hush-psubst/emptytick.right
+++ b/shell/hush_test/hush-psubst/emptytick.right
@@ -1,17 +1,17 @@
0
0
hush: can't execute '': No such file or directory
-0
+127
hush: can't execute '': No such file or directory
-0
+127
0
0
0
0
hush: can't execute '': No such file or directory
-0
+127
hush: can't execute '': No such file or directory
-0
+127
0
0
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 a269f02..eaffafb 100755
--- a/shell/hush_test/hush-psubst/emptytick.tests
+++ b/shell/hush_test/hush-psubst/emptytick.tests
@@ -1,17 +1,13 @@
true; ``; echo $?
false; ``; echo $?
-# UNFIXED BUG. bash sets $? to 127:
true; `""`; echo $?
-# bash sets $? to 127:
false; `""`; echo $?
true; ` `; echo $?
false; ` `; echo $?
true; $(); echo $?
false; $(); echo $?
-# bash sets $? to 127:
true; $(""); echo $?
-# bash sets $? to 127:
false; $(""); echo $?
true; $( ); echo $?
false; $( ); echo $?