From: Daniel P. Berrange Date: Fri, 8 Jul 2016 12:51:49 +0000 (+0100) Subject: lxc: convert to typesafe virConf accessors X-Git-Tag: v2.1.0-rc1~182 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51eeb756d284c12389364c52670c19c5ffcb8db8;p=thirdparty%2Flibvirt.git lxc: convert to typesafe virConf accessors Signed-off-by: Daniel P. Berrange --- diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 96a0f47dc4..538bbbe87d 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 8340b1fea0..5fb4bb1b0d 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;