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/trunk@12482 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2012-05-02 19:57:58 +00:00
parent abd9669f93
commit f6460e219a

View File

@ -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;
@ -1354,7 +1356,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>) {
@ -1403,6 +1409,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;
@ -1576,6 +1589,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;
@ -1905,6 +1919,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";
@ -1916,7 +1931,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