From 6e6e9bebc27c6300f34e186092b3a441a3a9853e Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 4 Apr 2012 13:14:19 +0100 Subject: [PATCH] Add API for loading daemon config from in-memory blob Rename existing daemonConfigLoad API to daemonConfigLoadFile and add an alternative daemonConfigLoadData * daemon/libvirtd-config.c, daemon/libvirtd-config.h: Add daemonConfigLoadData and rename daemonConfigLoad to daemonConfigLoadFile * daemon/libvirtd.c: Update for renamed API --- daemon/libvirtd-config.c | 67 +++++++++++++++++++++++++++------------- daemon/libvirtd-config.h | 9 ++++-- daemon/libvirtd.c | 2 +- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index bfb70842f8..7776202eb6 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -350,26 +350,11 @@ daemonConfigFree(struct daemonConfig *data) VIR_FREE(data); } - -/* Read the config file if it exists. - * Only used in the remote case, hence the name. - */ -int -daemonConfigLoad(struct daemonConfig *data, - const char *filename, - bool allow_missing) +static int +daemonConfigLoadOptions(struct daemonConfig *data, + const char *filename, + virConfPtr conf) { - virConfPtr conf; - - if (allow_missing && - access(filename, R_OK) == -1 && - errno == ENOENT) - return 0; - - conf = virConfReadFile (filename, 0); - if (!conf) - return -1; - GET_CONF_INT (conf, filename, listen_tcp); GET_CONF_INT (conf, filename, listen_tls); GET_CONF_STR (conf, filename, tls_port); @@ -447,10 +432,50 @@ daemonConfigLoad(struct daemonConfig *data, GET_CONF_INT (conf, filename, keepalive_count); GET_CONF_INT (conf, filename, keepalive_required); - virConfFree (conf); return 0; error: - virConfFree (conf); return -1; } + + +/* Read the config file if it exists. + * Only used in the remote case, hence the name. + */ +int +daemonConfigLoadFile(struct daemonConfig *data, + const char *filename, + bool allow_missing) +{ + virConfPtr conf; + int ret; + + if (allow_missing && + access(filename, R_OK) == -1 && + errno == ENOENT) + return 0; + + conf = virConfReadFile(filename, 0); + if (!conf) + return -1; + + ret = daemonConfigLoadOptions(data, filename, conf); + virConfFree(conf); + return ret; +} + +int daemonConfigLoadData(struct daemonConfig *data, + const char *filename, + const char *filedata) +{ + virConfPtr conf; + int ret; + + conf = virConfReadMem(filedata, strlen(filedata), 0); + if (!conf) + return -1; + + ret = daemonConfigLoadOptions(data, filename, conf); + virConfFree(conf); + return ret; +} diff --git a/daemon/libvirtd-config.h b/daemon/libvirtd-config.h index 00e8d1cc94..082cb9cdf7 100644 --- a/daemon/libvirtd-config.h +++ b/daemon/libvirtd-config.h @@ -84,8 +84,11 @@ struct daemonConfig { int daemonConfigFilePath(bool privileged, char **configfile); struct daemonConfig* daemonConfigNew(bool privileged); void daemonConfigFree(struct daemonConfig *data); -int daemonConfigLoad(struct daemonConfig *data, - const char *filename, - bool allow_missing); +int daemonConfigLoadFile(struct daemonConfig *data, + const char *filename, + bool allow_missing); +int daemonConfigLoadData(struct daemonConfig *data, + const char *filename, + const char *filedata); #endif /* __LIBVIRTD_CONFIG_H__ */ diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index f1487772bd..460a552b9d 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -922,7 +922,7 @@ int main(int argc, char **argv) { /* Read the config file if it exists*/ if (remote_config_file && - daemonConfigLoad(config, remote_config_file, implicit_conf) < 0) { + daemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) { VIR_ERROR(_("Can't load config file '%s'"), remote_config_file); exit(EXIT_FAILURE); }