X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=PVE%2FAPIClient%2FTools.pm;fp=PVE%2FAPIClient%2FTools.pm;h=f0a9a8cc166aa7bec7099aee292da2e183c22370;hp=622ed6cc274afec993cd83f254f463f4b9be0b05;hb=74ad9c37644bcf79d0687e8a36ff37ec29c10206;hpb=4aba8d31fe4441125c4af295e67534797bb27bfb diff --git a/PVE/APIClient/Tools.pm b/PVE/APIClient/Tools.pm index 622ed6c..f0a9a8c 100644 --- a/PVE/APIClient/Tools.pm +++ b/PVE/APIClient/Tools.pm @@ -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;