[pve-devel] [PATCH access-control 3/4] add force option to kill_process_group

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Jul 28 15:32:43 CEST 2016


only kill -9 in force mode and only set force mode
when worker is done or it is not the first stop attempt.
---
 PVE/RPCEnvironment.pm | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/PVE/RPCEnvironment.pm b/PVE/RPCEnvironment.pm
index 95bb83f..a7e8a01 100644
--- a/PVE/RPCEnvironment.pm
+++ b/PVE/RPCEnvironment.pm
@@ -741,7 +741,7 @@ sub active_workers  {
 }
 
 my $kill_process_group = sub {
-    my ($pid, $pstart) = @_;
+    my ($pid, $pstart, $force) = @_;
 
     # send kill to process group (negative pid)
     my $kpid = -$pid;
@@ -749,6 +749,8 @@ my $kill_process_group = sub {
     # always send signal to all pgrp members
     kill(15, $kpid); # send TERM signal
 
+    return if !$force;
+
     # give max 5 seconds to shut down
     for (my $i = 0; $i < 5; $i++) {
 	return if !PVE::ProcFSTools::check_process_running($pid, $pstart);
@@ -769,7 +771,25 @@ sub check_worker {
     return 0 if !$running;
 
     if ($killit) {
-	&$kill_process_group($task->{pid}, $task->{pstart});
+	my $force = 1;
+	eval {
+	    my $stoptime = time();
+	    my $tlist = active_workers($upid, 1, $stoptime);
+	    PVE::Cluster::broadcast_tasklist($tlist);
+	    my $taskinfo;
+	    foreach my $t (@$tlist) {
+		if ($t->{upid} eq $upid) {
+		    $taskinfo = $t;
+		    last;
+		}
+	    }
+
+	    # first stop attempt
+	    $force = 0
+		if $taskinfo && $taskinfo->{stoptime} && $taskinfo->{stoptime} == $stoptime;
+	};
+	warn $@ if $@;
+	&$kill_process_group($task->{pid}, $task->{pstart}, $force);
 	return 0;
     }
 
@@ -1038,7 +1058,7 @@ sub fork_worker {
 	    }
 	}
 
-	&$kill_process_group($cpid, $pstart); # make sure it gets killed
+	&$kill_process_group($cpid, $pstart, 1); # make sure it gets killed
 
 	close($outfh);
 
-- 
2.1.4





More information about the pve-devel mailing list