From 503cd7c4fb04c849a1450f1c2a4acd158d488d6e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 9 Oct 2015 18:12:28 +0100 Subject: [PATCH] standalone-generate-dump-flight-runvars: Handle ^C properly This is all mad. Signed-off-by: Ian Jackson Acked-by: Ian Campbell --- v2: Updated comment with more accurate discussion, references to bash "trap - INT" bug, and proposed new shopt. No code change. --- standalone-generate-dump-flight-runvars | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/standalone-generate-dump-flight-runvars b/standalone-generate-dump-flight-runvars index d113927d..4217719f 100755 --- a/standalone-generate-dump-flight-runvars +++ b/standalone-generate-dump-flight-runvars @@ -52,8 +52,35 @@ perbranch () { flight=check_${branch//[-._]/_} } +# Good grief, handling background proceesses from shell is a pain. +# +# For stupid historical reasons, background processes start with +# SIGINT (and QUIT) ignored (SuSv3 2.11). bash does not currently +# offer a way to ask it not to do this; nor is there a reliable way to +# put the SIGINT handling back to normal. +# +# "trap - INT" can be used to put the handling back in recent versions +# of bash (eg Debian jessie), but earlier versions are buggy, so +# we use perl. +# +# However, there is still a race: if the signal arrives just after the +# fork, after the shell has (in the child) set it to to IGN, but +# before Perl has put it back, the child might still escape. +# There is no reasonable way to deal with this race. So the result +# may still be slightly racy in the case that s-g-d-f-r is ^C'd right +# after starting. +# +# Hopefully in the future we can fix this with something like +# "shopt -s no_async_sig_ignore". See +# https://lists.gnu.org/archive/html/bug-bash/2015-10/msg00077.html + for branch in $@; do perbranch + perl -e ' + $SIG{$_}=DFL foreach qw(INT QUIT HUP); + kill 1, $$ unless getppid=='$$'; + exec @ARGV or die $!; + ' \ ./standalone make-flight -f $flight $branch >$log 2>&1 & procs+=" $branch=$!" done -- 2.39.5