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

Re: Bug related to stdin/always/jobcontrol



On Thu, 22 Sep 2016 11:59:21 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> This (39331) broke fg'ing a function for me:
> 
> % print $ZSH_PATCHLEVEL 
> zsh-5.2-dev-1-401-g4e51079
> % f() { $EDITOR } 
> % f
> <press ^Z in the editor>
> zsh: suspended  f
> % fg
> [1]  + continued  f
> zsh: suspended (tty output)  f
> 
> After the 'fg' I get another prompt immediately, instead of being
> returend to $EDITOR.

I think this is a fairly straightforward additional race fix, luckily, at
least to get us to the point where known problems are fixed.

In the cases I was looking at before, the processes associated with the
SUPERJOB already existed, and there was no further opportunity of fixing
up the pgrp for the SUBJOB.  The fact those processes already existed
also determined the pgrp for the SUBJOB, which is what's being set here
that caused the case above to be mishandled.

In this case, there's no process associated with the SUPERJOB yet, but
that's OK: everything gets handled properly when there is one.  I think
the gleader of the SUBJOB doesn't need any further special handling here
(everything seems to work, anyway).  Process handling and SUPERJOB
creation are murkily separate, so I don't think this is (necessarily)
buggy.

There could well be more aspects as I certainly haven't got my mind
round everything --- in particular, I don't know for sure that the fact
the shell has registered processes associated with the superjob is
actually tied to the subjob's pgrp, which is what this test assumes,
just that that appears to be so in the cases I've tried.

pws

diff --git a/Src/exec.c b/Src/exec.c
index d924148..a5086c3 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1703,7 +1703,8 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 			    jobtab[list_pipe_job].stat |= STAT_SUPERJOB;
 			    jn->stat |= STAT_SUBJOB | STAT_NOPRINT;
 			    jn->other = pid;
-			    jn->gleader = jobtab[list_pipe_job].gleader;
+			    if (hasprocs(list_pipe_job))
+				jn->gleader = jobtab[list_pipe_job].gleader;
 			}
 			if ((list_pipe || last1) && hasprocs(list_pipe_job))
 			    killpg(jobtab[list_pipe_job].gleader, SIGSTOP);



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