]> git.proxmox.com Git - librados2-perl.git/commitdiff
detect forked connections
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 21 Jan 2014 11:04:05 +0000 (12:04 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 21 Jan 2014 11:06:49 +0000 (12:06 +0100)
Else more than one process can kill our worker!

PVE/RADOS.pm

index 76c9d7b9d0d9477067b143880206e7f7fa642ba7..c8044b7074ecbd8b3fe7264a6cacb0b341f60089 100644 (file)
@@ -83,6 +83,9 @@ my $kill_worker = sub {
 
     close($self->{child}) if defined($self->{child});
 
+    # only kill if we created the process
+    return if $self->{pid} != $$; 
+
     kill(9, $self->{cpid});
     waitpid($self->{cpid}, 0);
 };
@@ -92,6 +95,8 @@ my $sendcmd = sub {
 
     $expect_tag = '>' if !$expect_tag;
 
+    die "detected forked connection" if $self->{pid} != $$;
+
     my ($restag, $raw);
     my $code = sub {
        &$writedata($self->{child}, $cmd, $data) if $expect_tag ne 'S';
@@ -129,6 +134,7 @@ sub new {
     my $timeout = delete $params{timeout} || $rados_default_timeout;
 
     $self->{timeout} = $timeout;
+    $self->{pid} = $$;
 
     if ($cpid) { # parent
        close $parent;