[libvirt] [PATCH 08/10] util: Use consistent error preservation and restoration calls

John Ferlan jferlan at redhat.com
Tue Oct 15 17:37:26 UTC 2019


Provide some consistency over error message variable name and usage
when saving error messages across possible other errors or possibility
of resetting of the last error.

Instead of virSaveLastError paired up with virSetError and virFreeError,
we should use the newer virErrorPreserveLast and virRestoreError.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/util/vircgroup.c   | 18 ++++++++----------
 src/util/virfirewall.c |  6 ++++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index c6e4cf2dde..4c83e37ec4 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1168,13 +1168,12 @@ virCgroupNewMachineSystemd(const char *name,
     }
 
     if (virCgroupAddProcess(*group, pidleader) < 0) {
-        virErrorPtr saved = virSaveLastError();
+        virErrorPtr saved;
+
+        virErrorPreserveLast(&saved);
         virCgroupRemove(*group);
         virCgroupFree(group);
-        if (saved) {
-            virSetError(saved);
-            virFreeError(saved);
-        }
+        virErrorRestore(&saved);
     }
 
     return 0;
@@ -1220,13 +1219,12 @@ virCgroupNewMachineManual(const char *name,
         goto cleanup;
 
     if (virCgroupAddProcess(*group, pidleader) < 0) {
-        virErrorPtr saved = virSaveLastError();
+        virErrorPtr saved;
+
+        virErrorPreserveLast(&saved);
         virCgroupRemove(*group);
         virCgroupFree(group);
-        if (saved) {
-            virSetError(saved);
-            virFreeError(saved);
-        }
+        virErrorRestore(&saved);
     }
 
  done:
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index 0d4bfae8f8..62f404afd6 100644
--- a/src/util/virfirewall.c
+++ b/src/util/virfirewall.c
@@ -838,7 +838,9 @@ virFirewallApply(virFirewallPtr firewall)
         if (virFirewallApplyGroup(firewall, i) < 0) {
             VIR_DEBUG("Rolling back groups up to %zu for %p", i, firewall);
             size_t first = i;
-            VIR_AUTOPTR(virError) saved_error = virSaveLastError();
+            virErrorPtr saved_error;
+
+            virErrorPreserveLast(&saved_error);
 
             /*
              * Look at any inheritance markers to figure out
@@ -858,7 +860,7 @@ virFirewallApply(virFirewallPtr firewall)
                 virFirewallRollbackGroup(firewall, j);
             }
 
-            virSetError(saved_error);
+            virErrorRestore(&saved_error);
             VIR_DEBUG("Done rolling back groups for %p", firewall);
             goto cleanup;
         }
-- 
2.20.1




More information about the libvir-list mailing list