return -1;
}
-
-static char *
-virConnectGetConfigFilePath(void)
-{
- char *path;
- if (geteuid() == 0) {
- if (virAsprintf(&path, "%s/libvirt/libvirt.conf",
- SYSCONFDIR) < 0)
- return NULL;
- } else {
- char *userdir = virGetUserConfigDirectory();
- if (!userdir)
- return NULL;
-
- if (virAsprintf(&path, "%s/libvirt.conf",
- userdir) < 0) {
- VIR_FREE(userdir);
- return NULL;
- }
- VIR_FREE(userdir);
- }
-
- return path;
-}
-
-
-static int
-virConnectGetConfigFile(virConfPtr *conf)
-{
- char *filename = NULL;
- int ret = -1;
-
- *conf = NULL;
-
- if (!(filename = virConnectGetConfigFilePath()))
- goto cleanup;
-
- if (!virFileExists(filename)) {
- ret = 0;
- goto cleanup;
- }
-
- VIR_DEBUG("Loading config file '%s'", filename);
- if (!(*conf = virConfReadFile(filename, 0)))
- goto cleanup;
-
- ret = 0;
-
- cleanup:
- VIR_FREE(filename);
- return ret;
-}
-
#define URI_ALIAS_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
if (ret == NULL)
return NULL;
- if (virConnectGetConfigFile(&conf) < 0)
+ if (virConfLoadConfig(&conf, NULL) < 0)
goto failed;
if (name && name[0] == '\0')
virConfFree;
virConfFreeValue;
virConfGetValue;
+virConfLoadConfig;
virConfNew;
virConfReadFile;
virConfReadMem;
#include "viralloc.h"
#include "virfile.h"
#include "virstring.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_CONF
*len = use;
return use;
}
+
+static char *
+virConfLoadConfigPath(const char *name)
+{
+ char *path;
+ if (geteuid() == 0) {
+ if (virAsprintf(&path, "%s/libvirt/libvirt%s%s.conf",
+ SYSCONFDIR,
+ name ? "-" : "",
+ name ? name : "") < 0)
+ return NULL;
+ } else {
+ char *userdir = virGetUserConfigDirectory();
+ if (!userdir)
+ return NULL;
+
+ if (virAsprintf(&path, "%s/libvirt%s%s.conf",
+ userdir,
+ name ? "-" : "",
+ name ? name : "") < 0) {
+ VIR_FREE(userdir);
+ return NULL;
+ }
+ VIR_FREE(userdir);
+ }
+
+ return path;
+}
+
+int
+virConfLoadConfig(virConfPtr *conf, const char *name)
+{
+ char *path = NULL;
+ int ret = -1;
+
+ *conf = NULL;
+
+ if (!(path = virConfLoadConfigPath(name)))
+ goto cleanup;
+
+ if (!virFileExists(path)) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ VIR_DEBUG("Loading config file '%s'", path);
+ if (!(*conf = virConfReadFile(path, 0)))
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(path);
+ return ret;
+}
int virConfWriteMem(char *memory,
int *len,
virConfPtr conf);
+int virConfLoadConfig(virConfPtr *conf, const char *name);
#endif /* __VIR_CONF_H__ */