[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash 4.3 no longer handles traps when reading input with read
From: |
Chet Ramey |
Subject: |
Re: Bash 4.3 no longer handles traps when reading input with read |
Date: |
Sun, 13 Oct 2013 14:29:03 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
On 10/11/13 6:19 PM, konsolebox wrote:
> On Fri, Oct 11, 2013 at 10:06 PM, Chet Ramey <chet.ramey@case.edu
> <mailto:chet.ramey@case.edu>> wrote:
>
> The SIGCHLD handler was particularly bad, since children can die and
> interrupt
> the shell at any time. As an example, glibc uses internal locks
> extensively, especially within its malloc implementation, and running trap
> handlers when a signal arrives (or worse, longjmping back to saved state)
> caused deadlocks.
>
> The bash signal and trap handling is now much closer to the Posix model:
> minimal work done when the signal arrives, traps run when it is safe to
> do so. If the arriving signal causes certain system calls to return
> -1/EINTR, for example if a SIGINT interrupts read(2), bash will notice and
> check for pending traps. SIGCHLD doesn't behave like that.
>
>
> Thanks for the reply.
>
> I understand the possible effect of receiving multiple signals at once, but
> how are other signals different from it? If one would trap signals like
> SIGQUIT, SIGABRT, SIGINT, SIGHUP and SIGTERM for safe exitting of an
> interactive script e.g. during shutdown some of those signals could arrive
> quickly as well.
It's not a question of receiving multiple signals at once. It's a question
of running too much in a signal handler. Since Posix says you can only do
a certain small number of things in a signal handler, bash needs to do as
little as possible -- for both trapped signals and ones bash handles
internally -- and defer the real work until it's `safe'. In the case of
traps, this is generally at command boundaries.
Bash-4.3 handles signals and traps when a read run by the read builtin is
interrupted by a signal. I'm not sure that's the best thing to do,
since traps should really be run when commands finish, but we're going to
try it.
Since bash-4.2, bash has installed its SIGCHLD signal handler with
SA_RESTART, so a child death does not unexpectedly interrupt system calls.
There were several bug reports concerning this. So yes, SIGCHLD is
special.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/