Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15919

Re: "wait" loses signals

From Denys Vlasenko <dvlasenk@redhat.com>
Newsgroups gnu.bash.bug
Subject Re: "wait" loses signals
Date 2020-02-20 09:02 +0100
Message-ID <mailman.1224.1582185773.2412.bug-bash@gnu.org> (permalink)
References <750d460d-b8a4-4157-1488-9f4d9f973715@redhat.com> <35034c85-fd5a-5034-a2d5-e3903888069d@case.edu> <cf7adbec-e705-1071-34e1-50f8188f0edc@redhat.com>

Show all headers | View raw


On 2/19/20 9:30 PM, Chet Ramey wrote:
> On 2/19/20 5:29 AM, Denys Vlasenko wrote:
>> A bug report from Harald van Dijk:
>>
>> test2.sh:
>> trap 'kill $!; exit' TERM
>> { kill $$; exec sleep 9; } &
>> wait $!
>>
>> The above script ought exit quickly, and not leave a stray
>> "sleep" child:
>> (1) if "kill $$" signal is delivered before "wait",
>> then TERM trap will kill the child, and exit.
> 
> This strikes me as a shaky assumption, dependent on when the shell receives
> the SIGTERM and when it runs traps.

The undisputable fact is that after shell forks a child
to run the "{...} &" subshell, it will receive the SIGTERM signal.

And since it has a trap for it, it should be run.

> (There's nothing in POSIX that says
> when pending traps are processed. Bash runs them after commands.)

Yes, and here we are "after command", specifically after "{...} &" command.
Since we got a trapped signal, we must run its trap.

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: "wait" loses signals Denys Vlasenko <dvlasenk@redhat.com> - 2020-02-20 09:02 +0100

csiph-web