mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-30 18:47:04 +00:00
migrate: collect migration tunnel child process
use waitpid with WNO_HANG to check if the ssh tunnel child process is still running and collect at the same time if it exited. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
052702921e
commit
61b04c6d5a
@ -5,6 +5,7 @@ use warnings;
|
|||||||
use PVE::AbstractMigrate;
|
use PVE::AbstractMigrate;
|
||||||
use IO::File;
|
use IO::File;
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
|
use POSIX qw( WNOHANG );
|
||||||
use PVE::INotify;
|
use PVE::INotify;
|
||||||
use PVE::Tools;
|
use PVE::Tools;
|
||||||
use PVE::Cluster;
|
use PVE::Cluster;
|
||||||
@ -44,17 +45,28 @@ sub fork_command_pipe {
|
|||||||
sub finish_command_pipe {
|
sub finish_command_pipe {
|
||||||
my ($self, $cmdpipe, $timeout) = @_;
|
my ($self, $cmdpipe, $timeout) = @_;
|
||||||
|
|
||||||
|
my $cpid = $cmdpipe->{pid};
|
||||||
|
return if !defined($cpid);
|
||||||
|
|
||||||
my $writer = $cmdpipe->{writer};
|
my $writer = $cmdpipe->{writer};
|
||||||
my $reader = $cmdpipe->{reader};
|
my $reader = $cmdpipe->{reader};
|
||||||
|
|
||||||
$writer->close();
|
$writer->close();
|
||||||
$reader->close();
|
$reader->close();
|
||||||
|
|
||||||
my $cpid = $cmdpipe->{pid};
|
my $collect_child_process = sub {
|
||||||
|
my $res = waitpid($cpid, WNOHANG);
|
||||||
|
if (defined($res) && ($res == $cpid)) {
|
||||||
|
delete $cmdpipe->{cpid};
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if ($timeout) {
|
if ($timeout) {
|
||||||
for (my $i = 0; $i < $timeout; $i++) {
|
for (my $i = 0; $i < $timeout; $i++) {
|
||||||
return if !PVE::ProcFSTools::check_process_running($cpid);
|
return if &$collect_child_process();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,13 +76,16 @@ sub finish_command_pipe {
|
|||||||
|
|
||||||
# wait again
|
# wait again
|
||||||
for (my $i = 0; $i < 10; $i++) {
|
for (my $i = 0; $i < 10; $i++) {
|
||||||
return if !PVE::ProcFSTools::check_process_running($cpid);
|
return if &$collect_child_process();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->log('info', "ssh tunnel still running - terminating now with SIGKILL\n");
|
$self->log('info', "ssh tunnel still running - terminating now with SIGKILL\n");
|
||||||
kill 9, $cpid;
|
kill 9, $cpid;
|
||||||
sleep 1;
|
sleep 1;
|
||||||
|
|
||||||
|
$self->log('err', "ssh tunnel child process (PID $cpid) couldn't be collected\n")
|
||||||
|
if !&$collect_child_process();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fork_tunnel {
|
sub fork_tunnel {
|
||||||
|
Loading…
Reference in New Issue
Block a user