[libvirt] [PATCH 09/16] lxc: convert to typesafe virConf accessors

Daniel P. Berrange berrange at redhat.com
Mon Jul 11 09:45:28 UTC 2016


Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 src/lxc/lxc_conf.c | 49 +++++++++++++++----------------------------------
 src/lxc/lxc_conf.h |  2 +-
 2 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 96a0f47..538bbbe 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -252,51 +252,32 @@ virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
                        const char *filename)
 {
     virConfPtr conf;
-    virConfValuePtr p;
+    int ret = -1;
 
     /* Avoid error from non-existent or unreadable file. */
     if (access(filename, R_OK) == -1)
-        goto done;
+        return 0;
+
     conf = virConfReadFile(filename, 0);
     if (!conf)
-        goto done;
-
-#define CHECK_TYPE(name, typ) if (p && p->type != (typ)) {              \
-        virReportError(VIR_ERR_INTERNAL_ERROR,                          \
-                       "%s: %s: expected type " #typ,                   \
-                       filename, (name));                               \
-        virConfFree(conf);                                              \
-        return -1;                                                      \
-    }
-
-    p = virConfGetValue(conf, "log_with_libvirtd");
-    CHECK_TYPE("log_with_libvirtd", VIR_CONF_ULONG);
-    if (p) cfg->log_libvirtd = p->l;
-
-    p = virConfGetValue(conf, "security_driver");
-    CHECK_TYPE("security_driver", VIR_CONF_STRING);
-    if (p && p->str) {
-        if (VIR_STRDUP(cfg->securityDriverName, p->str) < 0) {
-            virConfFree(conf);
-            return -1;
-        }
-    }
+        return -1;
 
-    p = virConfGetValue(conf, "security_default_confined");
-    CHECK_TYPE("security_default_confined", VIR_CONF_ULONG);
-    if (p) cfg->securityDefaultConfined = p->l;
+    if (virConfGetValueBool(conf, "log_with_libvirtd", &cfg->log_libvirtd) < 0)
+        goto cleanup;
 
-    p = virConfGetValue(conf, "security_require_confined");
-    CHECK_TYPE("security_require_confined", VIR_CONF_ULONG);
-    if (p) cfg->securityRequireConfined = p->l;
+    if (virConfGetValueString(conf, "security_driver", &cfg->securityDriverName) < 0)
+        goto cleanup;
 
+    if (virConfGetValueBool(conf, "security_default_confined", &cfg->securityDefaultConfined) < 0)
+        goto cleanup;
 
-#undef CHECK_TYPE
+    if (virConfGetValueBool(conf, "security_require_confined", &cfg->securityRequireConfined) < 0)
+        goto cleanup;
 
+    ret = 0;
+ cleanup:
     virConfFree(conf);
-
- done:
-    return 0;
+    return ret;
 }
 
 virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver)
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index 8340b1f..5fb4bb1 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -59,7 +59,7 @@ struct _virLXCDriverConfig {
     char *autostartDir;
     char *stateDir;
     char *logDir;
-    int log_libvirtd;
+    bool log_libvirtd;
     int have_netns;
 
     char *securityDriverName;
-- 
2.7.4




More information about the libvir-list mailing list