zsh-workers
 help / Atom feed
* Jobs unexpectedly disowned
@ 2019-07-21  6:19 ` Roman Perepelitsa
  2019-07-21  6:20   ` Roman Perepelitsa
  2019-07-31 14:25   ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Roman Perepelitsa @ 2019-07-21  6:19 UTC (permalink / raw)
  To: Zsh hackers list

I'm seeing weird behavior with jobs getting disowned and I'm not sure
whether it's intended.

Code:

    function f1() { sleep 1 & }
    function f2() { sleep 1 &; true }

    function g1() { f1; jobs; wait }
    function g2() { f2; jobs; wait }

    echo g1; g1
    echo g2; g2

When ran from `zsh -df` I get this:

    g1
    [2] 31060
    [2]  + running    sleep 1
    [2]  + done       sleep 1

    g2
    [2] 31061

I expected the output from g2 to look the same as from g1 but it's
different. Somehow the background job gets disowned when f2 returns.
However, this doesn't happen if I call f2 directly instead of going
through g2.

    f2; jobs; wait
    [2] 31137
    [2]  + running    sleep 1
    [2]  + done       sleep 1

Is this behavior intended?

Roman.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Jobs unexpectedly disowned
  2019-07-21  6:19 ` Jobs unexpectedly disowned Roman Perepelitsa
@ 2019-07-21  6:20   ` Roman Perepelitsa
  2019-07-31 14:25   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Roman Perepelitsa @ 2019-07-21  6:20 UTC (permalink / raw)
  To: Zsh hackers list

P.S.

This is with ZSH from master (zsh-5.7.1-105-ga4f3df8).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Jobs unexpectedly disowned
  2019-07-21  6:19 ` Jobs unexpectedly disowned Roman Perepelitsa
  2019-07-21  6:20   ` Roman Perepelitsa
@ 2019-07-31 14:25   ` Peter Stephenson
  2019-08-01 21:00     ` Peter Stephenson
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2019-07-31 14:25 UTC (permalink / raw)
  To: zsh-workers

On Sun, 2019-07-21 at 08:19 +0200, Roman Perepelitsa wrote:
> I'm seeing weird behavior with jobs getting disowned and I'm not sure
> whether it's intended.
> 
>     function f2() { sleep 1 &; true }
>     function g2() { f2; jobs; wait }
> 
>     echo g2; g2
> 
> When ran from `zsh -df` I get this:
> 
>     g2
>     [2] 31061

We're not seeing job information because STAT_NOPRINT is being or'ed into the
job status by this code within execpline().

	    if (list_pipe || (pline_level && !(how & Z_TIMED)))
		jn->stat |= STAT_NOPRINT;

because pline_level is non-zero.  I think it's non-zero just because
we're inside the shell function at this point, but I don't understand
why that's supposed to make a difference, and I haven't understood how
this point in the code gets hold of the background job which (although I
haven't checked) should be one started with Z_ASYNC by a lower level
call to execpline().

I think pline_level is really there for stuff inside non-final bits of
pipelines, but this stuff is a bit obscure.  (No, really.)

I also haven't worked out what adding "true" has got to do with it, but
it does make the difference.

pws

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Jobs unexpectedly disowned
  2019-07-31 14:25   ` Peter Stephenson
@ 2019-08-01 21:00     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2019-08-01 21:00 UTC (permalink / raw)
  To: zsh-workers

On Wed, 2019-07-31 at 14:25 +0000, Peter Stephenson wrote:
> On Sun, 2019-07-21 at 08:19 +0200, Roman Perepelitsa wrote:
> > I'm seeing weird behavior with jobs getting disowned and I'm not sure
> > whether it's intended.
> >  
> >     function f2() { sleep 1 &; true }
> >     function g2() { f2; jobs; wait }
> >  
> >     echo g2; g2
> >  
> > When ran from `zsh -df` I get this:
> >  
> >     g2
> >     [2] 31061
> 
> We're not seeing job information because STAT_NOPRINT is being or'ed into the
> job status by this code within execpline().
> 
> 	    if (list_pipe || (pline_level && !(how & Z_TIMED)))
> 		jn->stat |= STAT_NOPRINT;
> 
> because pline_level is non-zero.

This might be good enough --- a job that's been backgrounded has
been told not to use the terminal and if it's semi-detached in
that fashion we probably want it to show up as job.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 2acb2c0bc..e81053d67 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1690,7 +1690,8 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 
 	    lastwj = thisjob = newjob;
 
-	    if (list_pipe || (pline_level && !(how & Z_TIMED)))
+	    if (list_pipe || (pline_level && !(how & Z_TIMED) &&
+			      !(jn->stat & STAT_NOSTTY)))
 		jn->stat |= STAT_NOPRINT;
 
 	    if (nowait) {


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20190721062030epcas2p2326b1b0c1779aba66272cc90656e2a29@epcas2p2.samsung.com>
2019-07-21  6:19 ` Jobs unexpectedly disowned Roman Perepelitsa
2019-07-21  6:20   ` Roman Perepelitsa
2019-07-31 14:25   ` Peter Stephenson
2019-08-01 21:00     ` Peter Stephenson

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox