]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: convert to typesafe virConf accessors
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 8 Jul 2016 12:51:49 +0000 (13:51 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Jul 2016 08:58:21 +0000 (09:58 +0100)
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/lxc/lxc_conf.c
src/lxc/lxc_conf.h

index 96a0f47dc46997e9ef88de5c50280676ba65f49d..538bbbe87d3f4ca9c0ef9e18f8078700f39d1dc1 100644 (file)
@@ -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)
index 8340b1fea0fac6131e319ace557b49729d0fbe7e..5fb4bb1b0d8f8c9ba1c023d5e689c6f83ea3fb3d 100644 (file)
@@ -59,7 +59,7 @@ struct _virLXCDriverConfig {
     char *autostartDir;
     char *stateDir;
     char *logDir;
-    int log_libvirtd;
+    bool log_libvirtd;
     int have_netns;
 
     char *securityDriverName;