[libvirt] [snmp PATCH 05/20] showError: Switch to less ancient error reporting

Michal Privoznik mprivozn at redhat.com
Thu Oct 18 12:26:43 UTC 2018


So far, the function calls virConnCopyLastError() which is
suboptimal since we have virGetLastErrorMessage(). Switch to
that.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 configure.ac      |  2 +-
 src/libvirtSnmp.c | 31 +++----------------------------
 2 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1b4112e..baac0e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ dnl
 
 
 dnl do we have libvirt installed?
-LIBVIRT_REQUIRED=0.9.0
+LIBVIRT_REQUIRED=1.0.6
 
 PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
 AC_SUBST(LIBVIRT_LIBS)
diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 111c97b..22cf8f0 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -76,36 +76,11 @@ stop(int sig)
 static void
 showError(virConnectPtr conn)
 {
-    int ret;
-    virErrorPtr err;
+    const char *err = virGetLastErrorMessage();
 
-    err = malloc(sizeof(*err));
-    if (NULL == err) {
-        printf("Could not allocate memory for error data\n");
-        goto out;
-    }
+    snmp_log(LOG_ERR, "libvirt reported: \"%s\"\n", err);
 
-    ret = virConnCopyLastError(conn, err);
-
-    switch (ret) {
-    case 0:
-        snmp_log(LOG_ERR, "No error found\n");
-        break;
-
-    case -1:
-        snmp_log(LOG_ERR, "Parameter error when attempting to get last error\n");
-        break;
-
-    default:
-        snmp_log(LOG_ERR, "libvirt reported: \"%s\"\n", err->message);
-        break;
-    }
-
-    virResetError(err);
-    free(err);
-
- out:
-    return;
+    virResetLastError();
 }
 
 
-- 
2.18.1




More information about the libvir-list mailing list