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

PATCH: 3.1.5-pws-17: read after pipeline bug



This looks like being an old bug, it's also in 3.0.5.

zsh -f
% echo foo | read foo; read foo
%

The (interactive) shell doesn't wait.  It turns out the read gets an EIO
--- repeatedly, so it's not a hang over from the previous read.

I discovered read foo </dev/tty also didn't work, while if there was an
intervening external command it did.  After almost two hours of fruitless
searching when I'd almost given up (oddly enough, this has happened to me
before, even with zsh), it occurred to me to wonder about tty process
groups, which get reset after an external command but not an internal one.
This seemed to be the problem.  So the following does the check for
resetting the process group even if the pipeline which just finished had a
builtin at its tail end.  Some version of this should go into 3.0.6.

--- Src/jobs.c.eio	Sat May  8 14:50:27 1999
+++ Src/jobs.c	Sat May  8 18:33:45 1999
@@ -180,11 +180,16 @@
     } else {                   /* job is done, so remember return value */
 	lastval2 = val;
 	/* If last process was run in the current shell, keep old status
-	 * and let it handle its own traps
+	 * and let it handle its own traps, but always allow the test
+	 * for the pgrp.
 	 */
-	if (job == thisjob && !(jn->stat & STAT_CURSH)) {
-	  lastval = val;
-	  inforeground = 1;
+	if (job == thisjob) {
+	    if (jn->stat & STAT_CURSH)
+		inforeground = 1;
+	    else {
+		lastval = val;
+		inforeground = 2;
+	    }
 	}
     }
 
@@ -223,7 +228,7 @@
      * process group from the shell, so the shell will not receive     *
      * terminal signals, therefore we we pretend that the shell got    *
      * the signal too.                                                 */
-    if (inforeground && isset(MONITOR) && WIFSIGNALED(status)) {
+    if (inforeground == 2 && isset(MONITOR) && WIFSIGNALED(status)) {
 	int sig = WTERMSIG(status);
 
 	if (sig == SIGINT || sig == SIGQUIT) {

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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