This function assumed df() will work or hang, but it can
also actually fail and return undef which results in
warnings - let's silence those.
---
 src/PVE/Tools.pm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 9ddcfda..7285c59 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -985,7 +985,8 @@ sub df {
        $pipe->writer();
        eval {
            my $df = Filesys::Df::df($path, 1);
-           print {$pipe} "$df->{blocks}\n$df->{used}\n$df->{bavail}\n";
+           print {$pipe} "$df->{blocks}\n$df->{used}\n$df->{bavail}\n"
+               if defined($df);
            $pipe->close();
        };
        if (my $err = $@) {
@@ -998,9 +999,9 @@ sub df {
     $pipe->reader();
 
     my $readvalues = sub {
-       $res->{total} = int((<$pipe> =~ /^(\d*)$/)[0]);
-       $res->{used}  = int((<$pipe> =~ /^(\d*)$/)[0]);
-       $res->{avail} = int((<$pipe> =~ /^(\d*)$/)[0]);
+       $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);
-- 
2.11.0


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to