virConnectGetConfig and virConnectGetConfigPath were static libvirt
methods, merely because there hasn't been any need for having them
internally exported yet. Since libvirt-admin also needs to reference
libvirt config file, 'xGetConfig' should be exported.
Besides moving, this patch also renames the methods accordingly,
as they are libvirt config specific.
---
src/libvirt.c | 55 +-----------------------------------------------
src/libvirt_private.syms | 1 +
src/util/virconf.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
src/util/virconf.h | 1 +
4 files changed, 55 insertions(+), 54 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 25a0040..e3c35e4 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -908,59 +908,6 @@ virGetVersion(unsigned long *libVer, const char *type
ATTRIBUTE_UNUSED,
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_-"
@@ -1078,7 +1025,7 @@ do_open(const char *name,
if (ret == NULL)
return NULL;
- if (virConnectGetConfigFile(&conf) < 0)
+ if (virConfLoadDefault(&conf) < 0)
goto failed;
if (name && name[0] == '\0')
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a835f18..98f3351 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1323,6 +1323,7 @@ virRun;
virConfFree;
virConfFreeValue;
virConfGetValue;
+virConfLoadDefault;
virConfNew;
virConfReadFile;
virConfReadMem;
diff --git a/src/util/virconf.c b/src/util/virconf.c
index 9f2d116..792e23c 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -38,6 +38,7 @@
#include "viralloc.h"
#include "virfile.h"
#include "virstring.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_CONF
@@ -1053,3 +1054,54 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf)
*len = use;
return use;
}
+
+static char *
+virConfLoadDefaultPath(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;
+}
+
+int
+virConfLoadDefault(virConfPtr *conf)
+{
+ char *filename = NULL;
+ int ret = -1;
+
+ *conf = NULL;
+
+ if (!(filename = virConfLoadDefaultPath()))
+ 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;
+}
diff --git a/src/util/virconf.h b/src/util/virconf.h
index 8037956..7dab84d 100644
--- a/src/util/virconf.h
+++ b/src/util/virconf.h
@@ -96,5 +96,6 @@ int virConfWriteFile(const char *filename,
int virConfWriteMem(char *memory,
int *len,
virConfPtr conf);
+int virConfLoadDefault(virConfPtr *conf);
#endif /* __VIR_CONF_H__ */
--
2.4.3