Author: jilles
Date: Sun Nov 24 23:12:13 2013
New Revision: 258535
URL: http://svnweb.freebsd.org/changeset/base/258535

Log:
  sh: Make <&0 disable the </dev/null implicit in a background command.
  
  Although <&0 does nothing, it is a redirection affecting standard input and
  should therefore disable the </dev/null redirection implicit in a background
  command.

Added:
  head/tools/regression/bin/sh/execution/bg10.0   (contents, props changed)
  head/tools/regression/bin/sh/execution/bg10.0.stdout   (contents, props 
changed)
Modified:
  head/bin/sh/redir.c

Modified: head/bin/sh/redir.c
==============================================================================
--- head/bin/sh/redir.c Sun Nov 24 22:53:49 2013        (r258534)
+++ head/bin/sh/redir.c Sun Nov 24 23:12:13 2013        (r258535)
@@ -69,6 +69,7 @@ __FBSDID("$FreeBSD$");
 struct redirtab {
        struct redirtab *next;
        int renamed[10];
+       int fd0_redirected;
 };
 
 
@@ -109,11 +110,14 @@ redirect(union node *redir, int flags)
                sv = ckmalloc(sizeof (struct redirtab));
                for (i = 0 ; i < 10 ; i++)
                        sv->renamed[i] = EMPTY;
+               sv->fd0_redirected = fd0_redirected;
                sv->next = redirlist;
                redirlist = sv;
        }
        for (n = redir ; n ; n = n->nfile.next) {
                fd = n->nfile.fd;
+               if (fd == 0)
+                       fd0_redirected = 1;
                if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) &&
                    n->ndup.dupfd == fd)
                        continue; /* redirect from/to same file descriptor */
@@ -134,8 +138,6 @@ redirect(union node *redir, int flags)
                        sv->renamed[fd] = i;
                        INTON;
                }
-               if (fd == 0)
-                       fd0_redirected++;
                openredirect(n, memory);
        }
        if (memory[1])
@@ -303,8 +305,6 @@ popredir(void)
 
        for (i = 0 ; i < 10 ; i++) {
                if (rp->renamed[i] != EMPTY) {
-                        if (i == 0)
-                                fd0_redirected--;
                        if (rp->renamed[i] >= 0) {
                                dup2(rp->renamed[i], i);
                                close(rp->renamed[i]);
@@ -314,6 +314,7 @@ popredir(void)
                }
        }
        INTOFF;
+       fd0_redirected = rp->fd0_redirected;
        redirlist = rp->next;
        ckfree(rp);
        INTON;

Added: head/tools/regression/bin/sh/execution/bg10.0
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/regression/bin/sh/execution/bg10.0       Sun Nov 24 23:12:13 
2013        (r258535)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+# The redirection overrides the </dev/null implicit in a background command.
+
+echo yes | ${SH} -c '{ cat & wait; } <&0'

Added: head/tools/regression/bin/sh/execution/bg10.0.stdout
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/regression/bin/sh/execution/bg10.0.stdout        Sun Nov 24 
23:12:13 2013        (r258535)
@@ -0,0 +1 @@
+yes
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to