aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-25 17:00:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-25 17:00:13 +0200
commitb7adf7ac32e65906932935daf3d7a02d94818e09 (patch)
tree5da2c3015695c5368b92326dff987f9f51723a1a
parentf11c6989ba40f6bed8c4b4f0b6b7578aba3a63f9 (diff)
downloadbusybox-w32-b7adf7ac32e65906932935daf3d7a02d94818e09.tar.gz
busybox-w32-b7adf7ac32e65906932935daf3d7a02d94818e09.tar.bz2
busybox-w32-b7adf7ac32e65906932935daf3d7a02d94818e09.zip
ash,hush: set exit code 127 in "sh /does/not/exist" case
Upstream commit 1 for ash: [ERROR] Allow the originator of EXERROR to set the exit status Some errors have exit status values specified by POSIX and it is therefore desirable to be able to set the exit status at the EXERROR source rather than in main.c. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Upstream commit 2 for ash: [INPUT] Use exit status 127 when the script to run does not exist This commit makes dash exit with return code 127 instead of 2 if started as non-interactive shell with a non-existent command_file specified as argument (or a directory), as documented in http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_14 The wrong exit code was reported by Clint Adams and Jari Aalto through http://bugs.debian.org/548743 http://bugs.debian.org/548687 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> NB: in fact, http://bugs.debian.org/548687 was not fixed by this: "sh /dir/" thinks that EISDIR error on read is EOF, and exits 0. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c3
-rw-r--r--shell/hush.c2
2 files changed, 3 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index d9595bb8f..9798a9675 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10234,6 +10234,7 @@ setinputfile(const char *fname, int flags)
10234 if (fd < 0) { 10234 if (fd < 0) {
10235 if (flags & INPUT_NOFILE_OK) 10235 if (flags & INPUT_NOFILE_OK)
10236 goto out; 10236 goto out;
10237 exitstatus = 127;
10237 ash_msg_and_raise_error("can't open '%s'", fname); 10238 ash_msg_and_raise_error("can't open '%s'", fname);
10238 } 10239 }
10239 if (fd < 10) { 10240 if (fd < 10) {
@@ -13403,8 +13404,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13403 reset(); 13404 reset();
13404 13405
13405 e = exception_type; 13406 e = exception_type;
13406 if (e == EXERROR)
13407 exitstatus = 2;
13408 s = state; 13407 s = state;
13409 if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) { 13408 if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) {
13410 exitshell(); 13409 exitshell();
diff --git a/shell/hush.c b/shell/hush.c
index 9b51f389e..d7a0d761e 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8409,7 +8409,9 @@ int hush_main(int argc, char **argv)
8409 G.global_argc--; 8409 G.global_argc--;
8410 G.global_argv++; 8410 G.global_argv++;
8411 debug_printf("running script '%s'\n", G.global_argv[0]); 8411 debug_printf("running script '%s'\n", G.global_argv[0]);
8412 xfunc_error_retval = 127; /* for "hush /does/not/exist" case */
8412 input = xfopen_for_read(G.global_argv[0]); 8413 input = xfopen_for_read(G.global_argv[0]);
8414 xfunc_error_retval = 1;
8413 remember_FILE(input); 8415 remember_FILE(input);
8414 install_special_sighandlers(); 8416 install_special_sighandlers();
8415 parse_and_run_file(input); 8417 parse_and_run_file(input);