]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
libvirt: Move config getters to util
authorErik Skultety <eskultet@redhat.com>
Mon, 12 Oct 2015 14:09:53 +0000 (16:09 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 30 Nov 2015 08:36:19 +0000 (09:36 +0100)
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
its config file, 'xGetConfig' should be exported.
Besides moving, this patch also renames the methods accordingly,
as they are libvirt config specific.

src/libvirt.c
src/libvirt_private.syms
src/util/virconf.c
src/util/virconf.h

index 25a004049a4029408f644584ca97252399f8900d..cde22d254142bacf8078704bec784ecc4174caf9 100644 (file)
@@ -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 (virConfLoadConfig(&conf, NULL) < 0)
         goto failed;
 
     if (name && name[0] == '\0')
index 42528a445b49929fb9448a7fe717febae0830c06..d6187cba1202c0378adc0a53fc0076d1ded5c284 100644 (file)
@@ -1332,6 +1332,7 @@ virRun;
 virConfFree;
 virConfFreeValue;
 virConfGetValue;
+virConfLoadConfig;
 virConfNew;
 virConfReadFile;
 virConfReadMem;
index 9f2d116319ef30ba013cd42c6287decf3bd83f8c..5915bc2f6d8db061f7915abe9e5c162a23bb734b 100644 (file)
@@ -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,58 @@ virConfWriteMem(char *memory, int *len, virConfPtr 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;
+}
index 80379560ea3771705e3f83a3b04b2a6102c74e99..239ab39b664e2ae9709f074e99e26a599937f441 100644 (file)
@@ -96,5 +96,6 @@ int virConfWriteFile(const char *filename,
 int virConfWriteMem(char *memory,
                     int *len,
                     virConfPtr conf);
+int virConfLoadConfig(virConfPtr *conf, const char *name);
 
 #endif /* __VIR_CONF_H__ */