Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh DEBUG changes: convert DEBUG TRACE() calls to new for...



details:   https://anonhg.NetBSD.org/src/rev/ac6acba3c49e
branches:  trunk
changeset: 825247:ac6acba3c49e
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Jul 05 19:58:10 2017 +0000

description:
DEBUG changes: convert DEBUG TRACE() calls to new format.
ALso, cause exec failures to always cause the shell to exit with
status 126 or 127, whatever the cause.  127 is intended for lookup
failures (and is used that way), 126 is used for anything else that
goes wrong (as in several other shells.)  We no longer use 2 (more easily
confused with an exit status of the command exec'd) for shell exec failures.

diffstat:

 bin/sh/exec.c |  36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)

diffs (83 lines):

diff -r f671e7feb73c -r ac6acba3c49e bin/sh/exec.c
--- a/bin/sh/exec.c     Wed Jul 05 19:54:21 2017 +0000
+++ b/bin/sh/exec.c     Wed Jul 05 19:58:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec.c,v 1.50 2017/06/17 07:22:12 kre Exp $    */
+/*     $NetBSD: exec.c,v 1.51 2017/07/05 19:58:10 kre Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)exec.c     8.4 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: exec.c,v 1.50 2017/06/17 07:22:12 kre Exp $");
+__RCSID("$NetBSD: exec.c,v 1.51 2017/07/05 19:58:10 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -144,18 +144,28 @@
 
        /* Map to POSIX errors */
        switch (e) {
-       case EACCES:
+       case EACCES:    /* particularly this (unless no search perm) */
+               /*
+                * should perhaps check if this EACCES is an exec()
+                * EACESS or a namei() EACESS - the latter should be 127
+                * - but not today
+                */
+       case EINVAL:    /* also explicitly these */
+       case ENOEXEC:
+       default:        /* and anything else */
                exerrno = 126;
                break;
-       case ENOENT:
+
+       case ENOENT:    /* these are the "pathname lookup failed" errors */
+       case ELOOP:
+       case ENOTDIR:
+       case ENAMETOOLONG:
                exerrno = 127;
                break;
-       default:
-               exerrno = 2;
-               break;
        }
-       TRACE(("shellexec failed for %s, errno %d, vforked %d, suppressint %d\n",
-               argv[0], e, vforked, suppressint ));
+       CTRACE(DBG_ERRS|DBG_CMDS|DBG_EVAL,
+           ("shellexec failed for %s, errno %d, vforked %d, suppressint %d\n",
+               argv[0], e, vforked, suppressint));
        exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC));
        /* NOTREACHED */
 }
@@ -186,7 +196,7 @@
                        exraise(EXSHELLPROC);
                }
 #ifdef DEBUG
-               TRACE(("execve(cmd=%s) returned ENOEXEC\n", cmd));
+               VTRACE(DBG_CMDS, ("execve(cmd=%s) returned ENOEXEC\n", cmd));
 #endif
                initshellproc();
                setinputfile(cmd, 0);
@@ -600,7 +610,8 @@
                if (fullname[0] == '/' && idx <= prev) {
                        if (idx < prev)
                                goto loop;
-                       TRACE(("searchexec \"%s\": no change\n", name));
+                       VTRACE(DBG_CMDS, ("searchexec \"%s\": no change\n",
+                           name));
                        goto success;
                }
                while (stat(fullname, &statb) < 0) {
@@ -643,7 +654,8 @@
                                goto loop;
                }
 #endif
-               TRACE(("searchexec \"%s\" returns \"%s\"\n", name, fullname));
+               VTRACE(DBG_CMDS, ("searchexec \"%s\" returns \"%s\"\n", name,
+                   fullname));
                INTOFF;
                if (act & DO_ALTPATH) {
                /*



Home | Main Index | Thread Index | Old Index