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

Re: process substitution and Ctrl-C



On Thu, 19 Aug 2010 08:32:37 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> If I try
> 
>     echo >>(cat; sleep 100)
> 
> then the shell is effectively frozen until "sleep 100" finishes, because
> "echo" is already gone and the process substitution is not interruptible,
> so nothing is paying attention to ^C or ^Z etc.

(This should have gone to zsh-workers ages ago but still hasn't.)

This is a separate problem.  It's not so much that the echo has gone as
that there are no processes in the tty process group to get the signal,
because the substitution is treated as asynchronous for the purposes of
job handling.  (In fact, I've decided I don't understand what
"asynchronous" means in this case, either.  We seem to have spent
chunks of the last twenty years making process substitution less and
less like an asynchronous process; first we started waiting for it to
finish, now we're passing signals to it.)

Any reactions to the following patch?  This makes the substitution
process always get the same signal as the rest of the command line.  If
that's an external process that would be interrupted, so you wouldn't
see the freeze, but even there without the patch the "sleep" carries
merrily on --- similar to Vincent's case.

The alternative is to make it synchronous only if the current job is
running within the shell.  I no longer really have any idea what the
intention is.

I'm assuming the other use of >(...), when not part of a redirection,
want identical treatment to whatever happens here.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.181
diff -p -u -r1.181 exec.c
--- Src/exec.c	15 Jul 2010 18:44:13 -0000	1.181
+++ Src/exec.c	19 Aug 2010 20:26:24 -0000
@@ -3828,7 +3828,7 @@ getproc(char *cmd, char **eptr)
 	zerr("can't open %s: %e", pnam, errno);
 	_exit(1);
     }
-    entersubsh(ESUB_ASYNC|ESUB_PGRP);
+    entersubsh(ESUB_PGRP);
     redup(fd, out);
 #else /* PATH_DEV_FD */
     int pipes[2];
@@ -3855,7 +3855,7 @@ getproc(char *cmd, char **eptr)
 	}
 	return pnam;
     }
-    entersubsh(ESUB_ASYNC|ESUB_PGRP);
+    entersubsh(ESUB_PGRP);
     redup(pipes[out], out);
     closem(FDT_UNUSED);   /* this closes pipes[!out] as well */
 #endif /* PATH_DEV_FD */
@@ -3905,7 +3905,7 @@ getpipe(char *cmd, int nullexec)
 	    addproc(pid, NULL, 1, &bgtime);
 	return pipes[!out];
     }
-    entersubsh(ESUB_ASYNC|ESUB_PGRP);
+    entersubsh(ESUB_PGRP);
     redup(pipes[out], out);
     closem(FDT_UNUSED);	/* this closes pipes[!out] as well */
     cmdpush(CS_CMDSUBST);

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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