]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Add helper for safe remembering of libvirt errors
authorPeter Krempa <pkrempa@redhat.com>
Tue, 11 Apr 2017 15:23:23 +0000 (17:23 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 12 Apr 2017 12:11:52 +0000 (14:11 +0200)
Avoid the annoying issue where the public object freeing APIs overwrite
the error set by helper functions, since they don't invoke the callback.

The new helper remembers the error only if no previous error was set.

tools/virsh-util.c
tools/vsh.c
tools/vsh.h

index e225d3332b649f5e3a451f121c6ac65c63e3af2e..79a38bb2343664e428a70c6ca832ddff9fbacc48 100644 (file)
@@ -158,6 +158,7 @@ virshDomainFree(virDomainPtr dom)
     if (!dom)
         return;
 
+    vshSaveLibvirtHelperError();
     virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */
 }
 
@@ -168,5 +169,6 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap)
     if (!snap)
         return;
 
+    vshSaveLibvirtHelperError();
     virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */
 }
index d2024be9188a172d388cc9814aa699e9723165d0..10a65c39f960c747c92117077de234b75bf9f870 100644 (file)
@@ -258,6 +258,21 @@ vshSaveLibvirtError(void)
     last_error = virSaveLastError();
 }
 
+
+/* Store libvirt error from helper API but don't overwrite existing errors */
+void
+vshSaveLibvirtHelperError(void)
+{
+    if (last_error)
+        return;
+
+    if (!virGetLastError())
+        return;
+
+    vshSaveLibvirtError();
+}
+
+
 /*
  * Reset libvirt error on graceful fallback paths
  */
index 8f5d1a69f712c746f8d63b7169638915823b29fb..2f686eba6a81b10c8d16a3266e1d26803f10fe7d 100644 (file)
@@ -341,6 +341,7 @@ void vshErrorHandler(void *opaque, virErrorPtr error);
 void vshReportError(vshControl *ctl);
 void vshResetLibvirtError(void);
 void vshSaveLibvirtError(void);
+void vshSaveLibvirtHelperError(void);
 
 /* file handling */
 char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);