From b163fdd29031a2ed4bf289862016fe1882a7290b Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 2 May 2012 19:57:06 +0000 Subject: [PATCH] Have xCAT instances more reliably relay abort commands and cleanly exit on ctrl-c by client git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@12480 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/sbin/xcatd | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index 92d1995cb..9321b08b9 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -158,7 +158,9 @@ $xcatdir = (($tmp and $tmp->{value}) ? $tmp->{value} : "/etc/xcat"); $sitetab->close; my $progname; +my $pipeexpected; $SIG{PIPE} = sub { + if ($pipeexpected) { return; } confess "SIGPIPE $$progname encountered a broken pipe (probably Ctrl-C by client)"; }; $progname = \$0; @@ -1353,7 +1355,11 @@ sub dispatch_callback { sub relay_dispatch { my $fds = shift; my $dispatch_cb = shift; - my @ready_ins = $fds->can_read(1); + my @ready_ins; + eval { + @ready_ins = $fds->can_read(1); + }; + if ($@) { undef $@; return 0; } foreach my $rin (@ready_ins) { my $data; if ($data = <$rin>) { @@ -1402,6 +1408,13 @@ sub dispatch_request { $dispatch_children=0; $SIG{CHLD} = \&dispatch_reaper; #sub {my $cpid; while (($cpid =waitpid(-1, WNOHANG)) > 0) { if ($dispatched_children{$cpid}) { delete $dispatched_children{$cpid}; $dispatch_children--; } } }; + $SIG{TERM} = $SIG{INT} = sub { + foreach (keys %dispatched_children) { + kill 2, $_; + } + }; + + my $onlyone=0; if (defined $reqs and (scalar(@{$reqs}) == 1)) { $onlyone=1; @@ -1575,6 +1588,7 @@ sub convey_response { } unless ($resp) { return; } $resp = freeze($resp); + $pipeexpected=1; #$resp = XMLout($resp,KeyAttr=>[], NoAttr=>1,RootName=>'xcatresponse'); #sanitize the response, to avoid being killed by non-printable bytes #$resp =~ tr/\011-\177/?/c; @@ -1904,6 +1918,7 @@ sub relay_fds { #Relays file descriptors from pipes to children to the SSL socke } $clientintr=XMLin($clientintr, SuppressEmpty=>undef,ForceArray=>1 ); if ($clientintr->{abortcommand}->[0]) { + $pipeexpected=1; print "Aborting..."; foreach (keys %plugin_children) { print "Sending INT to $_\n"; @@ -1915,7 +1930,7 @@ sub relay_fds { #Relays file descriptors from pipes to children to the SSL socke close($cin); } xCAT::MsgUtils->message("S", "Client abort requested"); - die; + exit(0); } } yield; #Give other processes, including children, explicit control, to avoid uselessly aggressive looping