From: Ron Yorston Date: Tue, 3 Jan 2017 10:18:23 +0000 (+0100) Subject: ash: fix error code regression X-Git-Tag: 1_27_0~294 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ea7d2f6ec0596789fc5b2e3fca3b7a602bfa2c26;p=oweals%2Fbusybox.git ash: fix error code regression The commit 'ash,hush: set exit code 127 in "sh /does/not/exist" case' only partly implemented the dash commit '[ERROR] Allow the originator of EXERROR to set the exit status'. This resulted in incorrect error codes for a syntax error: $ ) $ echo $? 0 or a redirection error for a special builtin: $ rm -f xxx $ eval cat Reported-by: Martijn Dekker Signed-off-by: Denys Vlasenko --- diff --git a/shell/ash.c b/shell/ash.c index 430e42a7b..7c53946ce 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1284,6 +1284,8 @@ ash_msg_and_raise_error(const char *msg, ...) { va_list ap; + exitstatus = 2; + va_start(ap, msg); ash_vmsg_and_raise(EXERROR, msg, ap); /* NOTREACHED */ @@ -9588,11 +9590,13 @@ evalcommand(union node *cmd, int flags) } if (status) { + bail: + exitstatus = status; + /* We have a redirection error. */ if (spclbltin > 0) raise_exception(EXERROR); - bail: - exitstatus = status; + goto out; } diff --git a/shell/ash_test/ash-misc/exitcode2.right b/shell/ash_test/ash-misc/exitcode2.right new file mode 100644 index 000000000..f7cb983c6 --- /dev/null +++ b/shell/ash_test/ash-misc/exitcode2.right @@ -0,0 +1,4 @@ +./test.sh: line 1: syntax error: unexpected ")" +Done:2 +./exitcode2.tests: line 11: can't open does_not_exist: no such file +Done:1 diff --git a/shell/ash_test/ash-misc/exitcode2.tests b/shell/ash_test/ash-misc/exitcode2.tests new file mode 100755 index 000000000..79a6ebd50 --- /dev/null +++ b/shell/ash_test/ash-misc/exitcode2.tests @@ -0,0 +1,12 @@ +# syntax error should return status 2 +cat >test.sh <test.sh <