From f0b9cac61c7a73e5900b94874c3c2a2ba69488db Mon Sep 17 00:00:00 2001 From: daniceexi Date: Thu, 6 Nov 2014 06:23:52 -0500 Subject: [PATCH] defect 4304: fixed several things: 1. how to handle ctrl+c; 2. handle the plugin process cannot be stopped by TERM signal to process group SSL_Listener. (make the plugin process locate in the SSL_listener process group); 3. Make DB Access process exits later than in processing request. --- perl-xCAT/xCAT/Table.pm | 3 +++ xCAT-server/sbin/xcatd | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 880c7388f..bbe2ddbc8 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -215,6 +215,9 @@ sub init_dbworker { exit(0); } } + + # sleep a while to make sure the client process has done + sleep 1.5; close($dbworkersocket); unlink($dbsockpath); exit 0; diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index a0b2a58e7..6fe1d1c1a 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -1153,7 +1153,7 @@ until ($quit) { if ($child == 0) { close($udpctl); $udpctl=0; - $SIG{TERM} = $SIG{INT} = {}; + $SIG{TERM} = $SIG{INT} = 'DEFAULT'; $SIG{CHLD} = \&generic_reaper; #THROTTLE $listener->close; @@ -1455,6 +1455,16 @@ sub plugin_command { # save the old signal my $old_sig_chld = $SIG{CHLD}; $SIG{CHLD} = \&plugin_reaper; #sub {my $plugpid; while (($plugpid = waitpid(-1, WNOHANG)) > 0) { if ($plugin_children{$plugpid}) { delete $plugin_children{$plugpid}; $plugin_numchildren--; } } }; + + # make the request handler process to take care all the plugin children + $SIG{TERM} = $SIG{INT} = sub { + foreach (keys %plugin_children) { + kill 2, $_; + } + $SIG{ALRM} = sub { xexit 0; }; # wait 1s for grace exit + alarm(1); + }; + my $check_fds; if ($sock) { $check_fds = new IO::Select; @@ -1559,7 +1569,6 @@ sub plugin_command { die; } if ($child == 0) { - setpgrp(0,0); if ($parfd) { #If xCAT is doing multiple requests in same communication PID, things would get unfortunate otherwise $parent_fd = $parfd; } @@ -1776,9 +1785,11 @@ 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, $_; - } + foreach (keys %dispatched_children) { + kill 2, $_; + } + $SIG{ALRM} = sub { xexit 0; }; # wait 1s for grace exit + alarm(1); }; # this is used to filter out the incorrect module that xcat command came into # Mainly useful for hierarchical environment on SN @@ -2398,7 +2409,7 @@ sub relay_fds { #Relays file descriptors from pipes to children to the SSL socke print "Aborting..."; foreach (keys %plugin_children) { print "Sending INT to $_\n"; - kill -15, $_; + kill 2, $_; } foreach my $cin ($fds->handles) { print $cin "die\n";