zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: 5.0.8 regression when waiting for suspended jobs
Date: Tue, 11 Aug 2015 16:56:55 -0700	[thread overview]
Message-ID: <150811165655.ZM31504@torch.brasslantern.com> (raw)
In-Reply-To: <150731085638.ZM15733@torch.brasslantern.com>

On Jul 31,  8:56am, Bart Schaefer wrote:
}
} zsh-5.0.7
}  - "wait $!" blocks (looping on repeated wait3() nonzero)
}  - "wait %1" returns immediately
}  - "wait" returns immediately
} 
} zsh-5.0.8
}  - "wait $!" loops but also printing status every time
}  - "wait %1" returns immediately
}  - "wait" returns immediately

I still only suspect what changed to make 5.0.8 different from 5.0.7 in
this regard, but here's what's going on:

- "wait $!" -

bin_fg() calls waitforpid() which discovers the job is stopped and goes
into a loop calling kill(pid, SIGCONT) to try to get the job to run
again.  In the 5.0.8 case, each time this happens the job briefly wakes
up, gets stopped with SIGTTIN, thus causes another SIGCHLD to go to the
parent zsh, which then prints the "suspended" message and loops right
back to kill(pid, SIGCONT) again.

All of this is exactly the same as in 5.0.7 except that because of the
SIGCONT change in workers/35032 we notice the stopped -> continued ->
stopped again status change and therefore print the new status even
though it's actually the same as the last time we printed the status,
because we skipped printing the "continued" status.  Or so I surmise.

- wait %1" -

bin_fg() calls zwaitjob() which does NOT do kill(pid, SIGCONT) instead
simply blocking forever waiting for a SIGCHLD that will never arrive.

If a signal *is* received and the waiting shell is a subshell, *then*
the awaited job is SIGCONT'd, but I don't recall why and it doesn't
matter for this bug anyway.

This does however raise the question of why zwaitjob() is not calling
waitforpid().  If it did so, we'd have the ksh behavior for all three
cases of "wait", and we could even add the bit where interrupting the
wait sends the signal through to the waited-for job.

- "wait" -

bin_fg() goes into a loop calling zwaitjob() on every entry in the job
table; i.e., identical to "wait %1" repeated for every job number.

======

So what do we do about this?  Skip the SIGCONT in waitforpid()?  Only
try SIGCONT once in waitforpid() rather than every time around the
loop?  Some other thing involving the WIFCONTINUED() test?  Assuming
we work that out, should zwaitjob() be changed to use waitforpid(), or
do we think someone is relying on the bash-like immediate return?


  parent reply	other threads:[~2015-08-11 23:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-30 14:32 Christian Neukirchen
2015-07-30 19:39 ` Bart Schaefer
2015-07-31  8:30   ` Christian Neukirchen
2015-07-31 15:56     ` Bart Schaefer
2015-07-31 17:28       ` Christian Neukirchen
2015-07-31 17:41         ` Bart Schaefer
2015-08-11 23:56       ` Bart Schaefer [this message]
2015-08-12  9:43         ` Peter Stephenson
2015-08-12 14:58           ` Bart Schaefer
2015-08-12 16:09             ` Peter Stephenson
2015-08-12 17:31               ` Bart Schaefer
2015-08-15  1:56                 ` Bart Schaefer
2015-08-16 17:37                   ` Peter Stephenson
2015-08-16 21:49                     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150811165655.ZM31504@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).