提交 4f4c3b13 编写于 作者: P Peter Krempa

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.
上级 010c8f0f
...@@ -158,6 +158,7 @@ virshDomainFree(virDomainPtr dom) ...@@ -158,6 +158,7 @@ virshDomainFree(virDomainPtr dom)
if (!dom) if (!dom)
return; return;
vshSaveLibvirtHelperError();
virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */
} }
...@@ -168,5 +169,6 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) ...@@ -168,5 +169,6 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap)
if (!snap) if (!snap)
return; return;
vshSaveLibvirtHelperError();
virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */ virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */
} }
...@@ -258,6 +258,21 @@ vshSaveLibvirtError(void) ...@@ -258,6 +258,21 @@ vshSaveLibvirtError(void)
last_error = virSaveLastError(); 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 * Reset libvirt error on graceful fallback paths
*/ */
......
...@@ -341,6 +341,7 @@ void vshErrorHandler(void *opaque, virErrorPtr error); ...@@ -341,6 +341,7 @@ void vshErrorHandler(void *opaque, virErrorPtr error);
void vshReportError(vshControl *ctl); void vshReportError(vshControl *ctl);
void vshResetLibvirtError(void); void vshResetLibvirtError(void);
void vshSaveLibvirtError(void); void vshSaveLibvirtError(void);
void vshSaveLibvirtHelperError(void);
/* file handling */ /* file handling */
char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册