From fa7f51b813518bc305a1d4231495940654570b5c Mon Sep 17 00:00:00 2001 From: John Levon Date: Mon, 9 Feb 2009 14:16:23 +0000 Subject: [PATCH] introduce virSaveLastError(), virFreeError() --- ChangeLog | 6 ++++++ include/libvirt/virterror.h | 2 ++ src/libvirt_public.syms | 6 ++++++ src/virterror.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/ChangeLog b/ChangeLog index 63c2b3b0ff..917b1fd6f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 9 14:07:51 GMT 2009 John Levon + + * include/libvirt/virterror.h: + * src/libvirt_public.syms: + * src/virterror.c: introduce virSaveLastError(), virFreeError() + Mon Feb 9 10:21:33 GMT 2009 Daniel P. Berrange * src/virsh.c: Limit readonly history to 500 to avoid unbounded diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 0f1f08c49f..d68201f1d2 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -172,8 +172,10 @@ typedef void (*virErrorFunc) (void *userData, virErrorPtr error); */ virErrorPtr virGetLastError (void); +virErrorPtr virSaveLastError (void); void virResetLastError (void); void virResetError (virErrorPtr err); +void virFreeError (virErrorPtr err); virErrorPtr virConnGetLastError (virConnectPtr conn); void virConnResetLastError (virConnectPtr conn); diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 0555c9074f..1422e4cea8 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -247,4 +247,10 @@ LIBVIRT_0.6.0 { } LIBVIRT_0.5.0; +LIBVIRT_0.6.1 { + global: + virFreeError; + virSaveLastError; +} LIBVIRT_0.6.0; + # .... define new API here using predicted next version number .... diff --git a/src/virterror.c b/src/virterror.c index 6c479f43d7..42a7cf578b 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -285,6 +285,27 @@ virCopyLastError(virErrorPtr to) return to->code; } +/** + * virSaveLastError: + * + * Save the last error into a new error object. + * + * Returns a pointer to the copied error or NULL if allocation failed. + * It is the caller's responsibility to free the error with + * virFreeError(). + */ +virErrorPtr +virSaveLastError(void) +{ + virErrorPtr to; + + if (VIR_ALLOC(to) < 0) + return NULL; + + virCopyLastError(to); + return to; +} + /** * virResetError: * @err: pointer to the virError to clean up @@ -303,6 +324,18 @@ virResetError(virErrorPtr err) memset(err, 0, sizeof(virError)); } +/** + * virFreeError: + * @err: error to free + * + * Resets and frees the given error. + */ +void +virFreeError(virErrorPtr err) +{ + virResetError(err); + VIR_FREE(err); +} /** * virResetLastError: