From: "Daniel P. Berrange" <berrange(a)redhat.com>
---
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 bfb7084..92ae678 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 00e8d1c..082cb9c 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 f148777..460a552 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);
}
--
1.7.7.6