[pve-devel] [PATCH v2 cluster 1/2] cluster: improve error handling when reading files

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Oct 11 14:24:56 CEST 2017


When querying file contents via IPC we return undef if the
file does not exist, but also on any other error. This is
potentially problematic as the ipcc_send_rec() xs function
returns undef on actual errors as well, while setting $!
(errno).

It's better to die in cases other than ENOENT. Before this,
pvesr would assume an empty replication config and an empty
vm list if pmxcfs wasn't running, which could then clear out
the entire local replication state file.

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
Changes to v1:
  Improved readability as requested by fabian ;-)

 data/PVE/Cluster.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 84e3cbf..999e955 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -2,7 +2,7 @@ package PVE::Cluster;
 
 use strict;
 use warnings;
-use POSIX qw(EEXIST);
+use POSIX qw(EEXIST ENOENT);
 use File::stat qw();
 use Socket;
 use Storable qw(dclone);
@@ -402,7 +402,10 @@ my $ipcc_get_config = sub {
     my $bindata = pack "Z*", $path;
     my $res = PVE::IPCC::ipcc_send_rec(6, $bindata);
     if (!defined($res)) {
-	return undef if ($! != 0);
+	if ($! != 0) {
+	    return undef if $! == ENOENT;
+	    die "$!\n";
+	}
 	return '';
     }
 
-- 
2.11.0




More information about the pve-devel mailing list