mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-07 19:37:11 +00:00
tools: df: handle a failing df
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.
This commit is contained in:
parent
45d51061bc
commit
e8c13610c4
@ -983,7 +983,8 @@ sub df {
|
|||||||
$pipe->writer();
|
$pipe->writer();
|
||||||
eval {
|
eval {
|
||||||
my $df = Filesys::Df::df($path, 1);
|
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();
|
$pipe->close();
|
||||||
};
|
};
|
||||||
if (my $err = $@) {
|
if (my $err = $@) {
|
||||||
@ -996,9 +997,9 @@ sub df {
|
|||||||
$pipe->reader();
|
$pipe->reader();
|
||||||
|
|
||||||
my $readvalues = sub {
|
my $readvalues = sub {
|
||||||
$res->{total} = int((<$pipe> =~ /^(\d*)$/)[0]);
|
$res->{total} = int(((<$pipe> // 0) =~ /^(\d*)$/)[0]);
|
||||||
$res->{used} = int((<$pipe> =~ /^(\d*)$/)[0]);
|
$res->{used} = int(((<$pipe> // 0) =~ /^(\d*)$/)[0]);
|
||||||
$res->{avail} = int((<$pipe> =~ /^(\d*)$/)[0]);
|
$res->{avail} = int(((<$pipe> // 0) =~ /^(\d*)$/)[0]);
|
||||||
};
|
};
|
||||||
eval {
|
eval {
|
||||||
run_with_timeout($timeout, $readvalues);
|
run_with_timeout($timeout, $readvalues);
|
||||||
|
Loading…
Reference in New Issue
Block a user