mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
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:
parent
010c8f0f26
commit
4f4c3b1397
@ -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 */
|
||||
}
|
||||
|
15
tools/vsh.c
15
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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user