From: ramyelkest Date: Sat, 5 May 2018 12:04:20 +0000 (+0100) Subject: util: virerror: Introduce virGetLastError{Code,Domain} public APIs X-Git-Tag: v4.5.0-rc1~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50e96bb2a18a1bd7c2e7c5585e4ba60759496121;p=thirdparty%2Flibvirt.git util: virerror: Introduce virGetLastError{Code,Domain} public APIs Many places in the code call virGetLastError() just to check the raised error code, or domain. However virGetLastError() can return NULL, so the code has to check for that first. This patch therefore introduces virGetLasError{Code,Domain} functions which always return a valid error code or domain respectively, thus dropping the need to perform any checks on the error object. Signed-off-by: Ramy Elkest Reviewed-by: Erik Skultety --- diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 3e7c7a02c7..5e58b6a3f9 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -344,6 +344,8 @@ void virResetLastError (void); void virResetError (virErrorPtr err); void virFreeError (virErrorPtr err); +int virGetLastErrorCode (void); +int virGetLastErrorDomain (void); const char * virGetLastErrorMessage (void); virErrorPtr virConnGetLastError (virConnectPtr conn); diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 958601b1a5..4f54b84f75 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -792,4 +792,10 @@ LIBVIRT_4.4.0 { virConnectBaselineHypervisorCPU; } LIBVIRT_4.1.0; +LIBVIRT_4.5.0 { + global: + virGetLastErrorCode; + virGetLastErrorDomain; +} LIBVIRT_4.4.0; + # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index c000b00436..93632dbdf7 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -271,6 +271,41 @@ virGetLastError(void) } +/** + * virGetLastErrorCode: + * + * Get the most recent error code (enum virErrorNumber). + * + * Returns the most recent error code, or VIR_ERR_OK if none is set. + */ +int +virGetLastErrorCode(void) +{ + virErrorPtr err = virLastErrorObject(); + if (!err) + return VIR_ERR_OK; + return err->code; +} + + +/** + * virGetLastErrorDomain: + * + * Get the most recent error domain (enum virErrorDomain). + * + * Returns a numerical value of the most recent error's origin, or VIR_FROM_NONE + * if none is set. + */ +int +virGetLastErrorDomain(void) +{ + virErrorPtr err = virLastErrorObject(); + if (!err) + return VIR_FROM_NONE; + return err->domain; +} + + /** * virGetLastErrorMessage: *