[PATCH 10/10] tools: Use consistent error preservation and restoration calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tools/virsh.c      | 7 ++-----
 tools/virt-admin.c | 7 ++-----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 4aae877160..a3553ddd36 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -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);
     }
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index c0cc0999cb..a820e7241d 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -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
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux