From: Ian Jackson Subject: [OSSTEST PATCH] standalone-generate-dump-flight-runvars: Handle ^C properly Date: Fri, 9 Oct 2015 18:13:05 +0100 Message-ID: <1444410785-1271-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZkbEJ-0003LE-Tm for xen-devel@lists.xenproject.org; Fri, 09 Oct 2015 17:13:16 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org This is all mad. Signed-off-by: Ian Jackson --- standalone-generate-dump-flight-runvars | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/standalone-generate-dump-flight-runvars b/standalone-generate-dump-flight-runvars index a1907b0..efedd5c 100755 --- a/standalone-generate-dump-flight-runvars +++ b/standalone-generate-dump-flight-runvars @@ -58,8 +58,32 @@ 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 offer a +# way to ask it not to do this. +# +# There is no way to reset this in bash (bash 4.2.37 manpage section +# on `trap' builtin), 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. So in the child we check our parent. +# +# I _think_ that that any signal which arrives before the assignment +# to $SIG{} will definitely have caused our parent to vanish and us to +# be reparented to pid 1 by the time we do the getppid check. But TBH +# I can't find any clear support for this requirement. So the result +# may still be slightly racy in the case that s-g-d-f-r is ^C'd right +# after starting. + 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 -- 1.7.10.4