Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: exec fd>>(list) freezes



Clint Adams wrote:
> In the past, "exec 8>>(grep a)" used to work; now it doesn't return.  Is
> this broken or am I confused?
...
> > Specifically, it worked in 4.0.9 and prior versions, but chokes on 4.1.1
> > and later.
> 
> Is this because of 18492?

Yes, it's now waiting for the grep process to finish.  This is
obviously inappropriate if the fd is being opened for the shell's
own future use.

A test for this might be sensible, but in this case the race which was
fixed by 18492 is intrinsic.  You don't even have a PID to wait for.
(If you had wanted one, you would have used a coprocess.)

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.76
diff -u -r1.76 exec.c
--- Src/exec.c	21 Oct 2004 00:33:50 -0000	1.76
+++ Src/exec.c	29 Oct 2004 10:01:39 -0000
@@ -2205,7 +2205,7 @@
 
     /* Do process substitutions */
     if (redir)
-	spawnpipes(redir);
+	spawnpipes(redir, nullexec);
 
     /* Do io redirections */
     while (redir && nonempty(redir)) {
@@ -3113,11 +3113,17 @@
 #endif   /* HAVE_FIFOS and PATH_DEV_FD not defined */
 }
 
-/* > >(...) or < <(...) (does not use named pipes) */
+/*
+ * > >(...) or < <(...) (does not use named pipes)
+ *
+ * If the second argument is 1, this is part of
+ * an "exec < <(...)" or "exec > >(...)" and we shouldn't
+ * wait for the job to finish before continuing.
+ */
 
 /**/
 static int
-getpipe(char *cmd)
+getpipe(char *cmd, int nullexec)
 {
     Eprog prog;
     int pipes[2], out = *cmd == Inang;
@@ -3133,7 +3139,8 @@
 	    zclose(pipes[!out]);
 	    return -1;
 	}
-	addproc(pid, NULL, 1, &bgtime);
+	if (!nullexec)
+	    addproc(pid, NULL, 1, &bgtime);
 	return pipes[!out];
     }
     entersubsh(Z_ASYNC, 1, 0, 0);
@@ -3157,11 +3164,17 @@
     pp[1] = movefd(pp[1]);
 }
 
-/* Do process substitution with redirection */
+/*
+ * Do process substitution with redirection
+ *
+ * If the second argument is 1, this is part of
+ * an "exec < <(...)" or "exec > >(...)" and we shouldn't
+ * wait for the job to finish before continuing.
+ */
 
 /**/
 static void
-spawnpipes(LinkList l)
+spawnpipes(LinkList l, int nullexec)
 {
     LinkNode n;
     Redir f;
@@ -3172,7 +3185,7 @@
 	f = (Redir) getdata(n);
 	if (f->type == REDIR_OUTPIPE || f->type == REDIR_INPIPE) {
 	    str = f->name;
-	    f->fd2 = getpipe(str);
+	    f->fd2 = getpipe(str, nullexec);
 	}
     }
 }

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author