]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virerror: Introduce virGetLastError{Code,Domain} public APIs
authorramyelkest <ramyelkest@gmail.com>
Sat, 5 May 2018 12:04:20 +0000 (13:04 +0100)
committerErik Skultety <eskultet@redhat.com>
Tue, 5 Jun 2018 16:44:05 +0000 (18:44 +0200)
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 <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
include/libvirt/virterror.h
src/libvirt_public.syms
src/util/virerror.c

index 3e7c7a02c7c45e0b208f9645db9c01261eb11db8..5e58b6a3f9ee2759a5b5da3c4d839be7777e797d 100644 (file)
@@ -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);
index 958601b1a5cd6927b92bd37bb2ae531d68b57681..4f54b84f75d7ab1b1274c720e7a17d03d57fe340 100644 (file)
@@ -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 ....
index c000b004368f9dc72b810ca7495b1d0c9596a887..93632dbdf7ffe183e7aae6ba631a584337b5a92a 100644 (file)
@@ -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:
  *