]> git.proxmox.com Git - pve-client.git/blobdiff - PVE/APIClient/Tools.pm
update files from pve-common
[pve-client.git] / PVE / APIClient / Tools.pm
index 622ed6cc274afec993cd83f254f463f4b9be0b05..f0a9a8cc166aa7bec7099aee292da2e183c22370 100644 (file)
@@ -922,7 +922,6 @@ sub run_fork_with_timeout {
 
     # avoid leaving a zombie if the parent gets interrupted
     my $sig_received;
-    local $SIG{INT} = sub { $sig_received++; };
 
     my $child = fork();
     if (!defined($child)) {
@@ -946,11 +945,17 @@ sub run_fork_with_timeout {
        POSIX::_exit(0);
     }
 
+    local $SIG{INT} = sub { $sig_received++; };
+    local $SIG{TERM} = sub {
+       $error //= "interrupted by unexpected signal\n";
+       kill('TERM', $child);
+    };
+
     $pipe_out->reader();
 
     my $readvalues = sub {
        local $/ = undef;
-       my $child_res = decode_json(scalar<$pipe_out>);
+       my $child_res = decode_json(readline_nointr($pipe_out));
        $res = $child_res->{result};
        $error = $child_res->{error};
     };
@@ -1596,4 +1601,16 @@ sub convert_size {
     return int($value);
 }
 
+# uninterruptible readline
+# retries on EINTR
+sub readline_nointr {
+    my ($fh) = @_;
+    my $line;
+    while (1) {
+       $line = <$fh>;
+       last if defined($line) || ($! != EINTR);
+    }
+    return $line;
+}
+
 1;