Source-Changes-HG archive

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

[src/trunk]: src/bin/sh DEBUG mode only change. Add some tracing. NFC (wi...



details:   https://anonhg.NetBSD.org/src/rev/f703eba19a43
branches:  trunk
changeset: 827863:f703eba19a43
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Nov 15 09:21:48 2017 +0000

description:
DEBUG mode only change.   Add some tracing.   NFC (without DEBUG).

diffstat:

 bin/sh/redir.c |  23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diffs (118 lines):

diff -r 25fb3b7fa6d2 -r f703eba19a43 bin/sh/redir.c
--- a/bin/sh/redir.c    Wed Nov 15 09:21:19 2017 +0000
+++ b/bin/sh/redir.c    Wed Nov 15 09:21:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: redir.c,v 1.58 2017/06/30 23:01:21 kre Exp $   */
+/*     $NetBSD: redir.c,v 1.59 2017/11/15 09:21:48 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)redir.c    8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: redir.c,v 1.58 2017/06/30 23:01:21 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.59 2017/11/15 09:21:48 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -67,6 +67,7 @@
 #include "memalloc.h"
 #include "mystring.h"
 #include "error.h"
+#include "show.h"
 
 
 #define EMPTY -2               /* marks an unused slot in redirtab */
@@ -278,6 +279,8 @@
                        eflags = 0;
                if ((f = open(fname, O_RDONLY|eflags)) < 0)
                        goto eopen;
+               VTRACE(DBG_REDIR, ("openredirect(< '%s') -> %d [%#x]",
+                   fname, f, eflags));
                if (eflags)
                        (void)fcntl(f, F_SETFL, fcntl(f, F_GETFL, 0) & ~eflags);
                break;
@@ -285,6 +288,7 @@
                fname = redir->nfile.expfname;
                if ((f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
                        goto ecreate;
+               VTRACE(DBG_REDIR, ("openredirect(<> '%s') -> %d", fname, f));
                break;
        case NTO:
                if (Cflag) {
@@ -310,11 +314,13 @@
                fname = redir->nfile.expfname;
                if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
                        goto ecreate;
+               VTRACE(DBG_REDIR, ("openredirect(> '%s') -> %d", fname, f));
                break;
        case NAPPEND:
                fname = redir->nfile.expfname;
                if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
                        goto ecreate;
+               VTRACE(DBG_REDIR, ("openredirect(>> '%s') -> %d", fname, f));
                break;
        case NTOFD:
        case NFROMFD:
@@ -326,13 +332,19 @@
                            (flags & REDIR_KEEP) == 0) < 0)
                                error("Redirect (from %d to %d) failed: %s",
                                    redir->ndup.dupfd, fd, strerror(errno));
-               } else
+                       VTRACE(DBG_REDIR, ("openredirect: %d%c&%d\n", fd,
+                           "<>"[redir->nfile.type==NTOFD], redir->ndup.dupfd));
+               } else {
                        (void) close(fd);
+                       VTRACE(DBG_REDIR, ("openredirect: %d%c&-\n", fd,
+                           "<>"[redir->nfile.type==NTOFD]));
+               }
                INTON;
                return;
        case NHERE:
        case NXHERE:
                f = openhere(redir);
+               VTRACE(DBG_REDIR, ("openredirect: %d<<...", fd));
                break;
        default:
                abort();
@@ -340,6 +352,7 @@
 
        cloexec = fd > 2 && (flags & REDIR_KEEP) == 0 && !posix;
        if (f != fd) {
+               VTRACE(DBG_REDIR, (" -> %d", fd));
                if (copyfd(f, fd, cloexec) < 0) {
                        int e = errno;
 
@@ -350,6 +363,7 @@
                close(f);
        } else if (cloexec)
                (void)fcntl(f, F_SETFD, FD_CLOEXEC);
+       VTRACE(DBG_REDIR, ("%s\n", cloexec ? " cloexec" : ""));
 
        INTON;
        return;
@@ -549,6 +563,7 @@
 {
        int i;
 
+       VTRACE(DBG_REDIR|DBG_OUTPUT, ("to_upper_fd(%d)", fd));
        if (big_sh_fd < 10)
                find_big_fd();
        do {
@@ -556,6 +571,7 @@
                if (i >= 0) {
                        if (fd != i)
                                close(fd);
+                       VTRACE(DBG_REDIR|DBG_OUTPUT, ("-> %d\n", i));
                        return i;
                }
                if (errno != EMFILE && errno != EINVAL)
@@ -569,6 +585,7 @@
         * if the reassignment failed.
         */
        (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
+       VTRACE(DBG_REDIR|DBG_OUTPUT, (" fails ->%d\n", fd));
        return fd;
 }
 



Home | Main Index | Thread Index | Old Index