bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "wait" loses signals


From: Chet Ramey
Subject: Re: "wait" loses signals
Date: Mon, 24 Feb 2020 11:18:11 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 2/24/20 3:59 AM, Robert Elz wrote:

> The relevance of this is that if a signal arrives while the wait command
> is executing (or as Chet suggested, while doing whatever housekeeping is
> needed to prepare to run it, like looking to see what command comes next)
> but before the relevant wait*() system call is running, the trap won't
> be run until after the wait command completes.

There are two separate cases here: if the signal arrives before the wait
command has begun executing (during `housekeeping') or if it arrives
after the wait command has begun running but before it calls whatever
system call it uses to wait for children.

The second case is relatively easy to solve; Jilles wrote a message
detailing the alternatives. Bash uses the longjmp-out-of-the-trap-signal-
handler mechanism. The trap handler only has to know that the wait builtin
is running and that there's a valid saved environment to longjmp to.

The first case is trickier: there's always going to be a window between
the time the shell checks for pending traps and the time the wait builtin
starts to run. You can't really close it unless you're willing to run the
trap out of the signal handler, which everyone agrees is a bad idea, but
you can squeeze it down to practially nothing.

I think I've got a way to close that and make signals that arrive in that
first case act as if they arrived `while the shell is waiting by means of
the wait utility'. It's not much code and not disruptive.

With that, bash runs the original test script (100,000 iterations) on RHEL7
and macOS without a `stray' sleep. It's in the git devel branch.

I'm going to defer the question of whether or not that's the `right' thing
to do -- people have been trying to make signals into an IPC mechanism
since Berkeley introduced `reliable signals'.

Can we all take a breath now?

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]