From: Jilles Tjoelker <jilles@stack.nl>
To: Kris Maglione <maglione.k@gmail.com>
Cc: dash@vger.kernel.org
Subject: Re: Job control bug in revision 3800d4934391b,
Date: Sat, 29 May 2010 01:09:13 +0200 [thread overview]
Message-ID: <20100528230913.GA55183@stack.nl> (raw)
In-Reply-To: <20100527202157.08a1fa53@gmail.com>
On Thu, May 27, 2010 at 08:21:57PM -0400, Kris Maglione wrote:
> I'm not sure how to describe this bug, but it's affected one of my
> scripts, and those of several of my users. Basically, we've had loops
> dieing when backgrounded programs exit. This is the simplest test case
> I can come up with:
> #!/bin/dash
> {
> echo foo
> sleep 1
> echo foo
> echo done>/dev/tty
> } | while read p; do
> ( echo good & ) &
> done
> echo done
> In versions prior to 3800d4934391b, the output would
> "good\ndone\ndone\ngood" (or some permutation thereof depending on
> system load), but from 3800d4934391b on, it's "good\ndone".
> The offending revision:
> [JOBS] Fix dowait signal race
I can reproduce this here. It happens because the child process exit's
SIGCHLD causes an EINTR on the read, which then fails.
While the above testcase works with FreeBSD sh, a similar script with a
trap on CHLD fails in both (and likely also in older dash):
#!/bin/dash
{
echo foo
sleep 1
echo foo
echo done>/dev/tty
} | { trap : CHLD; while read p; do
( echo good & ) &
done }
echo done
Most other shells do not seem to abort a read builtin for a trap. bash
and ksh93 execute the trap right away and then continue the read, while
mksh postpones it until the read is done. POSIX seems vague about it,
but a look at existing scripts suggests that traps should not abort a
read. Executing the trap right away is useful in case it does something
such as exiting, and should be safe given that traps are already invoked
from deeper levels of recursion of the interpreter. If the trap executes
a break, continue or return command outside its boundaries this should
abort the read.
--
Jilles Tjoelker
prev parent reply other threads:[~2010-05-28 23:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-28 0:21 Job control bug in revision 3800d4934391b, Kris Maglione
2010-05-28 4:53 ` Herbert Xu
2010-05-28 15:34 ` Kris Maglione
2010-05-28 22:43 ` Herbert Xu
2010-05-28 23:01 ` Kris Maglione
2010-05-28 23:10 ` Herbert Xu
2010-05-28 23:40 ` Herbert Xu
2010-05-29 0:00 ` Kris Maglione
2010-05-28 23:09 ` Jilles Tjoelker [this message]
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=20100528230913.GA55183@stack.nl \
--to=jilles@stack.nl \
--cc=dash@vger.kernel.org \
--cc=maglione.k@gmail.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox