]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Use consistent error preservation and restoration calls
authorJohn Ferlan <jferlan@redhat.com>
Thu, 6 Dec 2018 17:33:39 +0000 (12:33 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 16 Oct 2019 19:24:41 +0000 (15:24 -0400)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/vircgroup.c
src/util/virfirewall.c

index e5b1df56e8ef3bdbd7d5fc9f6c68a594cdf4522a..d824aee86d2e51b9c14d36a057f51a6b3d5a9af8 100644 (file)
@@ -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:
index cc1e2b34eaa2809832fb5909036a11c2124cf52d..c2e88ec38221b337c1f62c72973e3b2a420d2955 100644 (file)
@@ -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;
-            g_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;
         }