Currently, function virConnectGetConfigFile() is in src/libvirt.c, but this function is to manipulate configration file, so we move it to virconf.c could make it more generic. Signed-off-by: Chen Fan <chen.fan.fnst@xxxxxxxxxxxxxx> --- src/libvirt.c | 54 ------------------------------------------------ src/libvirt_private.syms | 2 +- src/util/virconf.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ src/util/virconf.h | 1 + 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 4454829..f8d5240 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -51,7 +51,6 @@ #include "viruuid.h" #include "viralloc.h" -#include "configmake.h" #include "intprops.h" #include "virconf.h" #if WITH_GNUTLS @@ -875,59 +874,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_-" diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2d12105..4fdde15 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1142,7 +1142,7 @@ virConfSetValue; virConfWalk; virConfWriteFile; virConfWriteMem; - +virConnectGetConfigFile; # util/vircrypto.h virCryptoHashString; diff --git a/src/util/virconf.c b/src/util/virconf.c index 55de0e9..a06e72d 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 @@ -1054,3 +1055,56 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf) *len = use; return use; } + + +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; +} + + +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; +} diff --git a/src/util/virconf.h b/src/util/virconf.h index 2a6b050..aacd1c1 100644 --- a/src/util/virconf.h +++ b/src/util/virconf.h @@ -106,5 +106,6 @@ int virConfWriteFile (const char *filename, int virConfWriteMem (char *memory, int *len, virConfPtr conf); +int virConnectGetConfigFile(virConfPtr *conf); #endif /* __VIR_CONF_H__ */ -- 1.8.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list