mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
libvirt: Move config getters to util
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.
This commit is contained in:
parent
48cd3dfa66
commit
c4bdff191b
@ -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')
|
||||
|
@ -1332,6 +1332,7 @@ virRun;
|
||||
virConfFree;
|
||||
virConfFreeValue;
|
||||
virConfGetValue;
|
||||
virConfLoadConfig;
|
||||
virConfNew;
|
||||
virConfReadFile;
|
||||
virConfReadMem;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user