Path: csiph.com!aioe.org!news.glorb.com!usenet.stanford.edu!not-for-mail From: Chet Ramey Newsgroups: gnu.bash.bug Subject: Re: Bug where SIGINT trap handler isn't called Date: Thu, 30 Jul 2015 14:23:15 -0400 Lines: 43 Approved: bug-bash@gnu.org Message-ID: References: <55919F53.7030409@fau.de> <5591E281.1020708@case.edu> <55A72D84.2040405@fau.de> <55AEF97A.5020608@case.edu> <55B4331A.4090804@fau.de> Reply-To: chet.ramey@case.edu NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1438280619 27580 208.118.235.17 (30 Jul 2015 18:23:39 GMT) X-Complaints-To: action@cs.stanford.edu Cc: chet.ramey@case.edu To: Patrick Plagwitz , bug-bash@gnu.org Envelope-to: bug-bash@gnu.org X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 In-Reply-To: <55B4331A.4090804@fau.de> X-Junkmail-Status: score=10/50, host=mpv5.cwru.edu X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 129.22.105.37 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: aioe.org gnu.bash.bug:11278 On 7/25/15 9:08 PM, Patrick Plagwitz wrote: > I think command substitution has two issues. Those are because > set_job_and_cleanup isn't called for the single child made for comsub. > (1) The bug that was fixed in the discussion you linked is still in for > comsub waits: > $ bash -c 'while [ "$(exec >&-; sleep 0.001)" = "" ]; do :; done' > sometimes requires two ^Cs to stop. > The reason seems to be the same race condition described in > http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00073.html > and in your and in my last mail. Checking last_command_exit_value == > (128 + SIGINT) in command_substitute reflects the way the now-called > child_caught_sigint was determined before the patch made during the > discussion (i.e. it doesn't implement the heuristics). I see what you're saying, but I tested that and it doesn't make a difference. In the (admittedly very few) cases where that command took two ^Cs to kill, child_caught_sigint was always 1. The issue is the same as it always was: the ^C happens after the child runs `exit(0)' and before the parent's waitpid call returns. That causes the waitpid to return with -1/EINTR, setting child_caught_sigint to 1, and the next waitpid call picks up the 0 exit status, meaning that it's not reset. > (2) Running the comsub version of one of the above scripts: > $ bash -c 'trap "echo trap; exit" INT; foo="$(exec >&-; python -c > "import time; time.sleep(10)")"; echo foo' > yields another result (it prints foo, not trap). This is the behavior > the original bug report was about and you already replied to it but is > the difference between comsub children and normal ones here intended? Yes. While the shell runs command substitutions synchronously, it does not consider them foreground jobs. The code to run a trap set on SIGINT if the foreground job exits due to SIGINT was added as a compromise with old behavior back in 1996 for bash-2.0 and is entrenched now. 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/