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

more on pipe bug



I've made some progress.  The simplest form required to show the bug
is something like:

% if true; then echo | more; fi

Any shell construct will do, with any builtin piped to anything that
uses the terminal.  (You only need a builtin on the left of the pipe
because it finishes faster.)

It seems to localise to what's going on in entersubsh() in exec.c, in
particular the code calling setpgrp() and attachtty().  With no outer
construct, i.e. `echo | more' on its own, the first chunk with the
list_pipe_job stuff (just before the first chunk in the patch below)
comes into play.  With the construct, it doesn't (I haven't checked
the logic why not), and since the `echo' job was forked first and
becomes the process group leader, the last alternative, a simple
setpgprp(), is chosen.  This falls over if the echo process already
finished.

So a simple fix (below) is just to check whether the setpgrp() failed
and in that case make the process a new job leader.  This fixes the
bug as described and is certainly an improvement on the current code,
since if setpgrp() does fail, this is the right thing to do about it.

*However* I don't understand the list_pipe stuff and it's quite
possible there is a bug there, in other words the first chunk should
be coming into effect here as with the plain `echo | more'.  It's
there to keep track of pipelines in the current shell, which this
certainly is.

Anyway, here's the simple fix.

*** Src/exec.c.pgrp	Thu Aug 15 12:38:56 1996
--- Src/exec.c	Thu Sep 19 11:45:24 1996
***************
*** 1872,1878 ****
  		    attachtty(jobtab[thisjob].gleader);
  	    }
  	}
! 	else if (!jobtab[thisjob].gleader) {
  	    jobtab[thisjob].gleader = getpid();
  	    if (list_pipe_job != thisjob &&
  		!jobtab[list_pipe_job].gleader)
--- 1872,1879 ----
  		    attachtty(jobtab[thisjob].gleader);
  	    }
  	}
! 	else if (!jobtab[thisjob].gleader ||
! 		 (setpgrp(0L, jobtab[thisjob].gleader) == -1)) {
  	    jobtab[thisjob].gleader = getpid();
  	    if (list_pipe_job != thisjob &&
  		!jobtab[list_pipe_job].gleader)
***************
*** 1880,1887 ****
  	    setpgrp(0L, jobtab[thisjob].gleader);
  	    if (how & Z_SYNC)
  		attachtty(jobtab[thisjob].gleader);
! 	} else
! 	    setpgrp(0L, jobtab[thisjob].gleader);
      }
      if (!fake)
  	subsh = 1;
--- 1881,1887 ----
  	    setpgrp(0L, jobtab[thisjob].gleader);
  	    if (how & Z_SYNC)
  		attachtty(jobtab[thisjob].gleader);
! 	}
      }
      if (!fake)
  	subsh = 1;

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



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