From 4f4c3b1397c4b5d16af75ddf9e1f087844904655 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 11 Apr 2017 17:23:23 +0200 Subject: [PATCH] vsh: Add helper for safe remembering of libvirt errors 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 | 2 ++ tools/vsh.c | 15 +++++++++++++++ tools/vsh.h | 1 + 3 files changed, 18 insertions(+) diff --git a/tools/virsh-util.c b/tools/virsh-util.c index e225d3332b..79a38bb234 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -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 */ } diff --git a/tools/vsh.c b/tools/vsh.c index d2024be918..10a65c39f9 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -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 */ diff --git a/tools/vsh.h b/tools/vsh.h index 8f5d1a69f7..2f686eba6a 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -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);