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.
This commit is contained in:
Peter Krempa 2017-04-11 17:23:23 +02:00
parent 010c8f0f26
commit 4f4c3b1397
3 changed files with 18 additions and 0 deletions

View 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 */
}

View 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
*/

View 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);