[libvirt] [PATCH] Introduce virCopyLastError()

# HG changeset patch # User john.levon@sun.com # Date 1233859424 28800 # Node ID dd8a1923aae38d9e36cb98a934af64450ecd85a2 # Parent 8086732c0e4250d26a4cfed2411e86b209712eb5 Introduce virCopyLastError() Allow applications to store a copy of the last error reported. Signed-off-by: John Levon <john.levon@sun.com> diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -172,6 +172,7 @@ typedef void (*virErrorFunc) (void *user */ virErrorPtr virGetLastError (void); +virErrorPtr virSaveLastError (void); void virResetLastError (void); void virResetError (virErrorPtr err); diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -247,4 +247,9 @@ LIBVIRT_0.6.0 { } LIBVIRT_0.5.0; +LIBVIRT_0.6.1 { + global: + virSaveLastError; +} LIBVIRT_0.6.0; + # .... define new API here using predicted next version number .... diff --git a/src/virterror.c b/src/virterror.c --- a/src/virterror.c +++ b/src/virterror.c @@ -286,6 +286,25 @@ virCopyLastError(virErrorPtr to) } /** + * virSaveLastError: + * + * Save the last error into a new error object. + * + * Returns a pointer to the copied error or NULL if allocation failed. + */ +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 *

On Thu, Feb 05, 2009 at 11:27:19AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1233859424 28800 # Node ID dd8a1923aae38d9e36cb98a934af64450ecd85a2 # Parent 8086732c0e4250d26a4cfed2411e86b209712eb5 Introduce virCopyLastError()
Allow applications to store a copy of the last error reported.
Signed-off-by: John Levon <john.levon@sun.com>
ACK, though in the comment for virSaveLastError can you add an explicit note saying the caller must use virResetError to release memory associated with the virErrorPtr object once done. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Thu, Feb 05, 2009 at 08:16:57PM +0000, Daniel P. Berrange wrote:
On Thu, Feb 05, 2009 at 11:27:19AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1233859424 28800 # Node ID dd8a1923aae38d9e36cb98a934af64450ecd85a2 # Parent 8086732c0e4250d26a4cfed2411e86b209712eb5 Introduce virCopyLastError()
Allow applications to store a copy of the last error reported.
Signed-off-by: John Levon <john.levon@sun.com>
ACK, though in the comment for virSaveLastError can you add an explicit note saying the caller must use virResetError to release memory associated with the virErrorPtr object once done.
Actually, I see virResetError doesn't actually free the virErrorPtr itself, only the strings within it. Looks like we might want to have a virErrorFree() API to go along with it Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
john.levon@sun.com