[pve-devel] [PATCH v3 1/3] migrate: collect migration tunnel child process
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Jun 1 12:09:39 CEST 2016
As we open2 it we also need to collect it to avoid zombies
Omit timeout as its only used once and so we can use a static
wait time.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
PVE/QemuMigrate.pm | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index a288627..bfa2277 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -5,6 +5,7 @@ use warnings;
use PVE::AbstractMigrate;
use IO::File;
use IPC::Open2;
+use POSIX qw( WNOHANG );
use PVE::INotify;
use PVE::Tools;
use PVE::Cluster;
@@ -42,7 +43,10 @@ sub fork_command_pipe {
}
sub finish_command_pipe {
- my ($self, $cmdpipe, $timeout) = @_;
+ my ($self, $cmdpipe) = @_;
+
+ my $cpid = $cmdpipe->{pid};
+ return undef if !$cpid;
my $writer = $cmdpipe->{writer};
my $reader = $cmdpipe->{reader};
@@ -50,27 +54,22 @@ sub finish_command_pipe {
$writer->close();
$reader->close();
- my $cpid = $cmdpipe->{pid};
-
- if ($timeout) {
- for (my $i = 0; $i < $timeout; $i++) {
- return if !PVE::ProcFSTools::check_process_running($cpid);
- sleep(1);
+ # collect child process
+ for (my $i = 1; $i < 20; $i++) {
+ my $waitpid = waitpid($cpid, WNOHANG);
+ last if (defined($waitpid) && ($waitpid == $cpid));
+
+ if ($i == 10) {
+ $self->log('info', "ssh tunnel still running - terminating now with SIGTERM");
+ kill(15, $cpid);
+ } elsif ($i >= 15) {
+ $self->log('info', "ssh tunnel still running - terminating now with SIGKILL");
+ kill(9, $cpid);
}
+ sleep (1);
}
- $self->log('info', "ssh tunnel still running - terminating now with SIGTERM\n");
- kill(15, $cpid);
-
- # wait again
- for (my $i = 0; $i < 10; $i++) {
- return if !PVE::ProcFSTools::check_process_running($cpid);
- sleep(1);
- }
-
- $self->log('info', "ssh tunnel still running - terminating now with SIGKILL\n");
- kill 9, $cpid;
- sleep 1;
+ delete $cmdpipe->{cpid};
}
sub fork_tunnel {
@@ -114,7 +113,7 @@ sub finish_tunnel {
};
my $err = $@;
- $self->finish_command_pipe($tunnel, 30);
+ $self->finish_command_pipe($tunnel);
die $err if $err;
}
--
2.1.4
More information about the pve-devel
mailing list