bug-bash
[Top][All Lists]
Advanced

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

Re: Execution continuing after SIGINT received


From: Kevin Brodsky
Subject: Re: Execution continuing after SIGINT received
Date: Sat, 5 Aug 2017 18:41:39 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 05/08/2017 15:53, Chet Ramey wrote:
> On 8/4/17 7:52 PM, Kevin Brodsky wrote:
>
>> When Bash receives SIGINT while executing a command, it normally waits
>> for the command to complete, and then aborts execution. However, it
>> looks like somehow, this is not the case if the command handles SIGINT,
>> and execution continues after the command completes. For instance:
> The question of what happens when bash receives SIGINT while waiting for a
> foreground job to complete has come up many times in the past.
>
> See this for a good discussion of the issue:
>
> https://www.cons.org/cracauer/sigint.html
>
> The basic idea is that the user intends a keyboard-generated SIGINT to go
> to the foreground process; that process gets to decide how to handle it;
> and bash reacts accordingly.  If the process dies to due SIGINT, bash acts
> as if it received the SIGINT; if it does not, bash assumes the process
> handled it and effectively ignores it.
>
> Consider a process (emacs is the usual example) that uses SIGINT for its
> own purposes as a normal part of operation. If you run that program in a
> script, you don't want the shell aborting the script unexpectedly as a
> result.
>
> Chet

Thank you for your answer Chet. The article you linked is extremely
informative, I wasn't aware of the various possible strategies shells
can use to handle SIGINT!

So in summary, there is no bug on the Bash side, it simply implements
the WCE strategy, which does what the user wants... as long as the
invoked commands are well-behaved! And I just got very unlucky, as I did
stumble upon a misbehaved program, and all the other shells I tried
don't implement WCE... Some more experimentations showed that all three
(dash, mksh and zsh) implement WUE (I would have expected zsh to follow
Bash?).

Knowing this, it's now clear that the bug is on the Python side, as it
uses exit(1) when receiving SIGINT instead of doing the signal()/kill()
dance mentioned in the article. Other interpreters like Perl or Ruby
behave correctly, which confirms that there's a problem with Python. To
be fair, killing oneself when receiving SIGINT is quite
counter-intuitive, POSIX is not helping here.

Thanks,
Kevin



reply via email to

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