From 95ab036840d7fbb72a44aed3611de250d145abc7 Mon Sep 17 00:00:00 2001 From: GONG Jie Date: Wed, 12 Oct 2016 18:28:54 +0800 Subject: [PATCH] Fix github issue #448. From now on, send SIGINT signal to the whole process group of the xCAT plug-in. --- xCAT-server/sbin/xcatd | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index ded392492..2cffabf5c 100644 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -1748,7 +1748,11 @@ sub plugin_command { # make the request handler process to take care all the plugin children $SIG{TERM} = $SIG{INT} = sub { foreach (keys %plugin_children) { + # Send signal to the whole process group + kill 'INT', -$_; kill 'INT', $_; + kill 'TERM', -$_; + kill 'TERM', $_; } $SIG{ALRM} = sub { xexit 0; }; # wait 1s for grace exit alarm(1); @@ -1873,6 +1877,14 @@ sub plugin_command { binmode($parfd, ':utf8'); binmode($pfd, ':utf8'); $child = xCAT::Utils->xfork; + unless (defined $child) { + xCAT::MsgUtils->message("S", "Fork failed"); + die; + } + # Fix github issue #448. For the child process, setpgrp() + # here. In this way, the parent can send SIGINT or SIGTERM + # to all the process group. + setpgrp unless $child; } else { if ($req_back) { $req = dclone($req_back); @@ -1881,10 +1893,6 @@ sub plugin_command { } $child = 0; } - unless (defined $child) { - xCAT::MsgUtils->message("S", "Fork failed"); - die; - } if ($child == 0) { if ($parfd) { # If xCAT is doing multiple requests in same communication PID, things would get unfortunate otherwise $parent_fd = $parfd; @@ -2918,7 +2926,10 @@ sub relay_fds { # Relays file descriptors from pipes to children to the SSL sock print "Aborting..."; foreach (keys %plugin_children) { print "Sending INT to $_\n"; + # Send signal to the whole process group + kill 'INT', -$_; kill 'INT', $_; + kill 'TERM', -$_; kill 'TERM', $_; } foreach my $cin ($fds->handles) {