ash,hush: set exit code 127 in "sh /does/not/exist" case
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 25 Oct 2016 15:00:13 +0000 (17:00 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 25 Oct 2016 15:00:13 +0000 (17:00 +0200)
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>
shell/ash.c
shell/hush.c

index d9595bb8fd95735bee24923e034193c9db7a4e09..9798a96759571f935714e861da618e676aeddccd 100644 (file)
@@ -10234,6 +10234,7 @@ setinputfile(const char *fname, int flags)
        if (fd < 0) {
                if (flags & INPUT_NOFILE_OK)
                        goto out;
+               exitstatus = 127;
                ash_msg_and_raise_error("can't open '%s'", fname);
        }
        if (fd < 10) {
@@ -13403,8 +13404,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
                reset();
 
                e = exception_type;
-               if (e == EXERROR)
-                       exitstatus = 2;
                s = state;
                if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) {
                        exitshell();
index 9b51f389e385b7bcd9776788bec4fc40cd179ce1..d7a0d761e171c49b29f171593f405d69510332a8 100644 (file)
@@ -8409,7 +8409,9 @@ int hush_main(int argc, char **argv)
                G.global_argc--;
                G.global_argv++;
                debug_printf("running script '%s'\n", G.global_argv[0]);
+               xfunc_error_retval = 127; /* for "hush /does/not/exist" case */
                input = xfopen_for_read(G.global_argv[0]);
+               xfunc_error_retval = 1;
                remember_FILE(input);
                install_special_sighandlers();
                parse_and_run_file(input);