X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FTools.pm;h=d5373a4246062887bd778f35f4d2ac9cf2bb8bd1;hp=f91d35a1df52aa3a49acd8ebedf50147d08f8ceb;hb=4fdc9659e9aa86fee1a88afd79e879333618832d;hpb=ed61b9d67588465f101ec043a1e224608c833e02 diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index f91d35a..d5373a4 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -981,49 +981,16 @@ sub run_fork { sub df { my ($path, $timeout) = @_; - my $res = { - total => 0, - used => 0, - avail => 0, - }; - - my $pipe = IO::Pipe->new(); - my $child = fork(); - if (!defined($child)) { - warn "fork failed: $!\n"; - return $res; - } - - if (!$child) { - $pipe->writer(); - eval { - my $df = Filesys::Df::df($path, 1); - print {$pipe} "$df->{blocks}\n$df->{used}\n$df->{bavail}\n" - if defined($df); - $pipe->close(); - }; - if (my $err = $@) { - warn $err; - POSIX::_exit(1); - } - POSIX::_exit(0); - } + my $df = sub { return Filesys::Df::df($path, 1) }; - $pipe->reader(); + my $res = eval { run_fork_with_timeout($timeout, $df) } // {}; + warn $@ if $@; - my $readvalues = sub { - $res->{total} = int(((<$pipe> // 0) =~ /^(\d*)$/)[0]); - $res->{used} = int(((<$pipe> // 0) =~ /^(\d*)$/)[0]); - $res->{avail} = int(((<$pipe> // 0) =~ /^(\d*)$/)[0]); - }; - eval { - run_with_timeout($timeout, $readvalues); + return { + total => $res->{blocks} // 0, + used => $res->{used} // 0, + avail => $res->{bavail} // 0, }; - warn $@ if $@; - $pipe->close(); - kill('KILL', $child); - waitpid($child, 0); - return $res; } # UPID helper