]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
wrap possible problematic cfs_read_file calls in eval
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 8 Nov 2017 13:41:40 +0000 (14:41 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 9 Nov 2017 10:42:12 +0000 (11:42 +0100)
Wrap those calls to the cfs_read_file method, which may now also die
if there was a grave problem reading the file, into eval in all
methods which are used by the ha services.

The ones only used by API calls or CLI helpers are not wrapped, as
there it can be handled more gracefull (i.e., no watchdog is
running) and further, this is more intended to temporarily workaround
until we handle such an exception explicitly in the services - which
is a bit bigger change, so let's just go back to the old behavior for
now.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Config.pm
src/PVE/HA/Manager.pm

index bf37b04ff193969f8eed6592c6287e6fdba1faaf..e7e8b88b897bf1d5441788dc2fa5bc2d43ec08d9 100644 (file)
@@ -81,13 +81,13 @@ sub parse_resources_config {
 
 sub read_resources_config {
 
-    return cfs_read_file($ha_resources_config);
+    return eval { cfs_read_file($ha_resources_config) };
 }
 
 # checks if resource exists and sets defaults for unset values
 sub read_and_check_resources_config {
 
-    my $res = cfs_read_file($ha_resources_config);
+    my $res = eval { cfs_read_file($ha_resources_config) };
 
     my $vmlist = PVE::Cluster::get_vmlist();
     my $conf = {};
@@ -122,7 +122,7 @@ sub read_and_check_resources_config {
 
 sub read_group_config {
 
-    return cfs_read_file($ha_groups_config);
+    return eval { cfs_read_file($ha_groups_config) };
 }
 
 sub write_group_config {
@@ -140,7 +140,7 @@ sub write_resources_config {
 sub read_manager_status {
     my () = @_;
 
-    return cfs_read_file($manager_status_filename);
+    return eval { cfs_read_file($manager_status_filename) };
 }
 
 sub write_manager_status {
@@ -152,7 +152,7 @@ sub write_manager_status {
 sub read_fence_config {
     my () = @_;
 
-    cfs_read_file($ha_fence_config);
+    return eval { cfs_read_file($ha_fence_config) };
 }
 
 sub write_fence_config {
@@ -189,7 +189,8 @@ sub queue_crm_commands {
 sub read_crm_commands {
 
     my $code = sub {
-       my $data = cfs_read_file($crm_commands_filename);
+       my $data = eval { cfs_read_file($crm_commands_filename) };
+       return undef if !$data;
        cfs_write_file($crm_commands_filename, '');
        return $data;
     };
index 25a7398d732303cb223203ac6ba6caac452520d5..2933926ae47ed49006d743bfd7702d3a3577bc13 100644 (file)
@@ -328,7 +328,8 @@ sub update_crm_commands {
     my ($haenv, $ms, $ns, $ss) = ($self->{haenv}, $self->{ms}, $self->{ns}, $self->{ss});
 
     my $cmdlist = $haenv->read_crm_commands();
-    
+    return if !defined($cmdlist);
+
     foreach my $cmd (split(/\n/, $cmdlist)) {
        chomp $cmd;