[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/4] Switch libvirtd config loading code to use error APIs



From: "Daniel P. Berrange" <berrange redhat com>

Using VIR_ERROR means the test suite can't catch error messages
easily. Use the proper error reporting APIs instead
---
 daemon/libvirtd-config.c |   56 ++++++++++++++++++++++++++++-----------------
 daemon/libvirtd.c        |    6 ++++-
 2 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index 92ae678..1f4a6fb 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -28,13 +28,17 @@
 #include "memory.h"
 #include "virterror_internal.h"
 #include "logging.h"
-#include "virnetserver.h"
+#include "rpc/virnetserver.h"
 #include "configmake.h"
-#include "remote_protocol.h"
-#include "remote_driver.h"
+#include "remote/remote_protocol.h"
+#include "remote/remote_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_CONF
 
+#define virConfError(code, ...)                                      \
+    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,              \
+                         __FUNCTION__, __LINE__, __VA_ARGS__)
+
 /* Allocate an array of malloc'd strings from the config file, filename
  * (used only in diagnostics), using handle "conf".  Upon error, return -1
  * and free any allocated memory.  Otherwise, save the array in *list_arg
@@ -52,14 +56,17 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
     switch (p->type) {
     case VIR_CONF_STRING:
         if (VIR_ALLOC_N(list, 2) < 0) {
-            VIR_ERROR(_("failed to allocate memory for %s config list"), key);
+            virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                         _("failed to allocate memory for %s config list"),
+                         key);
             return -1;
         }
         list[0] = strdup (p->str);
         list[1] = NULL;
         if (list[0] == NULL) {
-            VIR_ERROR(_("failed to allocate memory for %s config list value"),
-                      key);
+            virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                         _("failed to allocate memory for %s config list value"),
+                         key);
             VIR_FREE(list);
             return -1;
         }
@@ -71,14 +78,17 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
         for (pp = p->list; pp; pp = pp->next)
             len++;
         if (VIR_ALLOC_N(list, 1+len) < 0) {
-            VIR_ERROR(_("failed to allocate memory for %s config list"), key);
+            virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                         _("failed to allocate memory for %s config list"),
+                         key);
             return -1;
         }
         for (i = 0, pp = p->list; pp; ++i, pp = pp->next) {
             if (pp->type != VIR_CONF_STRING) {
-                VIR_ERROR(_("remoteReadConfigFile: %s: %s:"
-                            " must be a string or list of strings"),
-                          filename, key);
+                virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                             _("remoteReadConfigFile: %s: %s:"
+                               " must be a string or list of strings"),
+                             filename, key);
                 VIR_FREE(list);
                 return -1;
             }
@@ -88,8 +98,9 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
                 for (j = 0 ; j < i ; j++)
                     VIR_FREE(list[j]);
                 VIR_FREE(list);
-                VIR_ERROR(_("failed to allocate memory for %s config list value"),
-                          key);
+                virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                             _("failed to allocate memory for %s config list value"),
+                             key);
                 return -1;
             }
 
@@ -99,9 +110,10 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
     }
 
     default:
-        VIR_ERROR(_("remoteReadConfigFile: %s: %s:"
-                    " must be a string or list of strings"),
-                  filename, key);
+        virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                     _("remoteReadConfigFile: %s: %s:"
+                       " must be a string or list of strings"),
+                     filename, key);
         return -1;
     }
 
@@ -115,10 +127,11 @@ checkType (virConfValuePtr p, const char *filename,
            const char *key, virConfType required_type)
 {
     if (p->type != required_type) {
-        VIR_ERROR(_("remoteReadConfigFile: %s: %s: invalid type:"
-                    " got %s; expected %s"), filename, key,
-                  virConfTypeName (p->type),
-                  virConfTypeName (required_type));
+        virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                     _("remoteReadConfigFile: %s: %s: invalid type:"
+                       " got %s; expected %s"), filename, key,
+                     virConfTypeName (p->type),
+                     virConfTypeName (required_type));
         return -1;
     }
     return 0;
@@ -176,8 +189,9 @@ static int remoteConfigGetAuth(virConfPtr conf, const char *key, int *auth, cons
     } else if (STREQ(p->str, "polkit")) {
         *auth = VIR_NET_SERVER_SERVICE_AUTH_POLKIT;
     } else {
-        VIR_ERROR(_("remoteReadConfigFile: %s: %s: unsupported auth %s"),
-                  filename, key, p->str);
+        virConfError(VIR_ERR_CONFIG_UNSUPPORTED,
+                     _("remoteReadConfigFile: %s: %s: unsupported auth %s"),
+                     filename, key, p->str);
         return -1;
     }
 
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 460a552..f4d5029 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -923,7 +923,11 @@ int main(int argc, char **argv) {
     /* Read the config file if it exists*/
     if (remote_config_file &&
         daemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
-        VIR_ERROR(_("Can't load config file '%s'"), remote_config_file);
+        virErrorPtr err = virGetLastError();
+        if (err && err->message)
+            VIR_ERROR(_("%s"), err->message);
+        else
+            VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
         exit(EXIT_FAILURE);
     }
 
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]