]> xenbits.xensource.com Git - libvirt.git/commitdiff
tools: Use consistent error preservation and restoration calls
authorJohn Ferlan <jferlan@redhat.com>
Thu, 6 Dec 2018 17:33:57 +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>
tools/virsh.c
tools/virt-admin.c

index 4aae87716078c1354fd4621543254e17d6f1e157..a3553ddd36daf29f7529452f86fd592ee15a1c95 100644 (file)
@@ -93,7 +93,7 @@ virshCatchDisconnect(virConnectPtr conn,
         virErrorPtr error;
         char *uri;
 
-        error = virSaveLastError();
+        virErrorPreserveLast(&error);
         uri = virConnectGetURI(conn);
 
         switch ((virConnectCloseReason) reason) {
@@ -114,10 +114,7 @@ virshCatchDisconnect(virConnectPtr conn,
         vshError(ctl, _(str), NULLSTR(uri));
         VIR_FREE(uri);
 
-        if (error) {
-            virSetError(error);
-            virFreeError(error);
-        }
+        virErrorRestore(&error);
         disconnected++;
         vshEventDone(ctl);
     }
index e2ed272a04cbd5ef7dcbf7798556fdaf46ac4c74..3aada5f963c8212ca1a4ee26b52daf38580b2c6c 100644 (file)
@@ -124,7 +124,7 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn G_GNUC_UNUSED,
     if (reason == VIR_CONNECT_CLOSE_REASON_CLIENT)
         return;
 
-    error = virSaveLastError();
+    virErrorPreserveLast(&error);
     uri = virAdmConnectGetURI(conn);
 
     switch ((virConnectCloseReason) reason) {
@@ -146,10 +146,7 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn G_GNUC_UNUSED,
     vshError(ctl, _(str), NULLSTR(uri));
     VIR_FREE(uri);
 
-    if (error) {
-        virSetError(error);
-        virFreeError(error);
-    }
+    virErrorRestore(&error);
 }
 
 static int