diff options
author | Ron Yorston <rmy@pobox.com> | 2017-01-03 11:18:23 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-03 11:18:23 +0100 |
commit | ea7d2f6ec0596789fc5b2e3fca3b7a602bfa2c26 (patch) | |
tree | 80bf9f7fae0b7dc5c8cd0047129ce792ceb37ec9 | |
parent | bddbeb82bfeac8d4795ab995eae09109c048e9df (diff) | |
download | busybox-w32-ea7d2f6ec0596789fc5b2e3fca3b7a602bfa2c26.tar.gz busybox-w32-ea7d2f6ec0596789fc5b2e3fca3b7a602bfa2c26.tar.bz2 busybox-w32-ea7d2f6ec0596789fc5b2e3fca3b7a602bfa2c26.zip |
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 <xxx
$ echo $?
0
Signed-off-by: Ron Yorston <rmy@pobox.com>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 8 | ||||
-rw-r--r-- | shell/ash_test/ash-misc/exitcode2.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-misc/exitcode2.tests | 12 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/exitcode2.right | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/exitcode2.tests | 12 |
5 files changed, 38 insertions, 2 deletions
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, ...) | |||
1284 | { | 1284 | { |
1285 | va_list ap; | 1285 | va_list ap; |
1286 | 1286 | ||
1287 | exitstatus = 2; | ||
1288 | |||
1287 | va_start(ap, msg); | 1289 | va_start(ap, msg); |
1288 | ash_vmsg_and_raise(EXERROR, msg, ap); | 1290 | ash_vmsg_and_raise(EXERROR, msg, ap); |
1289 | /* NOTREACHED */ | 1291 | /* NOTREACHED */ |
@@ -9588,11 +9590,13 @@ evalcommand(union node *cmd, int flags) | |||
9588 | } | 9590 | } |
9589 | 9591 | ||
9590 | if (status) { | 9592 | if (status) { |
9593 | bail: | ||
9594 | exitstatus = status; | ||
9595 | |||
9591 | /* We have a redirection error. */ | 9596 | /* We have a redirection error. */ |
9592 | if (spclbltin > 0) | 9597 | if (spclbltin > 0) |
9593 | raise_exception(EXERROR); | 9598 | raise_exception(EXERROR); |
9594 | bail: | 9599 | |
9595 | exitstatus = status; | ||
9596 | goto out; | 9600 | goto out; |
9597 | } | 9601 | } |
9598 | 9602 | ||
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 @@ | |||
1 | ./test.sh: line 1: syntax error: unexpected ")" | ||
2 | Done:2 | ||
3 | ./exitcode2.tests: line 11: can't open does_not_exist: no such file | ||
4 | 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 @@ | |||
1 | # syntax error should return status 2 | ||
2 | cat >test.sh <<EOF | ||
3 | ) | ||
4 | EOF | ||
5 | chmod +x test.sh | ||
6 | $THIS_SH ./test.sh | ||
7 | echo Done:$? | ||
8 | rm -f test.sh | ||
9 | |||
10 | # redirection error with special builtin should return status 1 | ||
11 | (eval cat <does_not_exist) | ||
12 | echo Done:$? | ||
diff --git a/shell/hush_test/hush-misc/exitcode2.right b/shell/hush_test/hush-misc/exitcode2.right new file mode 100644 index 000000000..0a57b9b1b --- /dev/null +++ b/shell/hush_test/hush-misc/exitcode2.right | |||
@@ -0,0 +1,4 @@ | |||
1 | hush: syntax error: unexpected ) | ||
2 | Done:2 | ||
3 | hush: can't open 'does_not_exist': No such file or directory | ||
4 | Done:1 | ||
diff --git a/shell/hush_test/hush-misc/exitcode2.tests b/shell/hush_test/hush-misc/exitcode2.tests new file mode 100755 index 000000000..79a6ebd50 --- /dev/null +++ b/shell/hush_test/hush-misc/exitcode2.tests | |||
@@ -0,0 +1,12 @@ | |||
1 | # syntax error should return status 2 | ||
2 | cat >test.sh <<EOF | ||
3 | ) | ||
4 | EOF | ||
5 | chmod +x test.sh | ||
6 | $THIS_SH ./test.sh | ||
7 | echo Done:$? | ||
8 | rm -f test.sh | ||
9 | |||
10 | # redirection error with special builtin should return status 1 | ||
11 | (eval cat <does_not_exist) | ||
12 | echo Done:$? | ||