From a6ecddb029a4bde4b2d09f5e77dca079672e9d47 Mon Sep 17 00:00:00 2001 From: zhaoertao Date: Wed, 14 Sep 2011 03:27:30 +0000 Subject: [PATCH] Fix bug 3301782: cancelling hdw_svr commands doesn't kill the fsp-api git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10517 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/perl/xCAT/PPC.pm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/perl/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm index 51ee7f8b9..c08b9ad0b 100644 --- a/xCAT-server/lib/perl/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -409,6 +409,12 @@ sub process_command { $remain_node = (); foreach my $hash ( @$nodes ) { $SIG{CHLD} = sub { my $pid = 0; while (($pid = waitpid(-1, WNOHANG)) > 0) { $hw->{$pid_owner->{$pid}}--; $children--; } }; + $SIG{INT} = $SIG{TERM} = $SIG{KILL} = sub { #prepare to process job termination and propogate it down + foreach my $pid (keys %{$pid_owner}) { + &kill_children_by_pid($pid); + } + exit 0; + }; while ( $children >= $request->{ppcmaxp} ) { my $handlednodes={}; @@ -453,7 +459,14 @@ sub process_command { } elsif ( $request->{command} =~ /^rspconfig$/&& exists( $request->{opt}->{resetnet} ) ) { runcmd( $request ); } else { + my %pid_owner = (); $SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) { $children--; } }; + $SIG{INT} = $SIG{TERM} = $SIG{KILL} = sub { #prepare to process job termination and propogate it down + foreach my $pid (keys %pid_owner) { + &kill_children_by_pid($pid); + } + exit 0; + }; my $hw; my $sessions; @@ -481,8 +494,9 @@ sub process_command { } $hw = @$_[0]; - my ($pipe) = fork_cmd( @$_[0], @$_[1], $request ); + my ($pipe,$pid) = fork_cmd( @$_[0], @$_[1], $request ); if ( $pipe ) { + $pid_owner{$pid} = $pid; $fds->add( $pipe ); $children++; } @@ -543,6 +557,20 @@ ENDOFFORK: return(0); } +sub kill_children_by_pid { + my $pid = shift; + my @pids = `ps -o pid,ppid -e`; + for my $a_pid (@pids) { + if( $a_pid =~ /\s*(\d*)\s*(\d*)/ ) { + my $tmp_pid = $1; + my $tmp_ppid = $2; + if($tmp_ppid == $pid) { + kill 9, $tmp_pid; + } + } + } +} + ########################################################################## # updateNodeStatus ##########################################################################