Not all files we want to find using virFileFindResource{,Full} are
generated when libvirt is built, some of them (such as RNG schemas) are
distributed with sources. The current API was not able to find source
files if libvirt was built in VPATH.
Both RNG schemas and cpu_map.xml are distributed in source tarball.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/Makefile.am | 2 ++
src/conf/domain_conf.c | 2 +-
src/cpu/cpu_map.c | 2 +-
src/driver.c | 2 +-
src/fdstream.c | 2 +-
src/locking/lock_driver_lockd.c | 2 +-
src/locking/lock_manager.c | 2 +-
src/lxc/lxc_conf.c | 2 +-
src/network/bridge_driver.c | 2 +-
src/remote/remote_driver.c | 2 +-
src/storage/storage_backend_disk.c | 4 ++--
src/util/virfile.c | 30 ++++++++++++++++--------------
12 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index b41c6d4..a938d7e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@
abs_builddir = $(shell pwd)
abs_topbuilddir = $(shell cd .. && pwd)
abs_srcdir = $(shell cd $(srcdir) && pwd)
+abs_topsrcdir = $(shell cd $(srcdir)/.. && pwd)
# No libraries with the exception of LIBXML should be listed
# here. List them against the individual XXX_la_CFLAGS targets
@@ -32,6 +33,7 @@ INCLUDES = -I../gnulib/lib \
-I$(srcdir)/util \
-DIN_LIBVIRT \
-Dabs_topbuilddir="\"$(abs_topbuilddir)\"" \
+ -Dabs_topsrcdir="\"$(abs_topsrcdir)\"" \
$(GETTEXT_CPPFLAGS)
AM_CFLAGS = $(LIBXML_CFLAGS) \
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b13cae8..2e35293 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12887,7 +12887,7 @@ virDomainDefParseXML(xmlDocPtr xml,
if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE) {
char *schema = virFileFindResource("domain.rng",
- "docs/schemas",
+ abs_topsrcdir "/docs/schemas",
PKGDATADIR "/schemas");
if (!schema)
return NULL;
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index b77f688..6130f8a 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -87,7 +87,7 @@ int cpuMapLoad(const char *arch,
char *mapfile;
if (!(mapfile = virFileFindResource("cpu_map.xml",
- "src/cpu",
+ abs_topsrcdir "/src/cpu",
PKGDATADIR)))
return -1;
diff --git a/src/driver.c b/src/driver.c
index 1be32ef..db03438 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -56,7 +56,7 @@ virDriverLoadModule(const char *name)
if (!(modfile = virFileFindResourceFull(name,
"libvirt_driver_",
".so",
- "src/.libs",
+ abs_topbuilddir "/src/.libs",
LIBDIR
"/libvirt/connection-driver",
"LIBVIRT_DRIVER_DIR")))
return NULL;
diff --git a/src/fdstream.c b/src/fdstream.c
index 18bd359..5d80fc2 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -641,7 +641,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
}
if (!(iohelper_path = virFileFindResource("libvirt_iohelper",
- "src",
+ abs_topbuilddir "/src",
LIBEXECDIR)))
goto error;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 2af3f22..8d184fe 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -253,7 +253,7 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool
privileged,
if (!privileged &&
!(daemonPath = virFileFindResourceFull("virtlockd",
NULL, NULL,
- "src",
+ abs_topbuilddir "/src",
SBINDIR,
"VIRTLOCKD_PATH")))
goto error;
diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
index ec90d04..f277f22 100644
--- a/src/locking/lock_manager.c
+++ b/src/locking/lock_manager.c
@@ -142,7 +142,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
if (!(modfile = virFileFindResourceFull(name,
NULL,
".so",
- "src/.libs",
+ abs_topbuilddir "/src/.libs",
LIBDIR "/libvirt/lock-driver",
"LIBVIRT_LOCK_MANAGER_PLUGIN_DIR")))
goto cleanup;
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index b6d1797..d1a3be5 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -94,7 +94,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
}
if (!(lxc_path = virFileFindResource("libvirt_lxc",
- "src",
+ abs_topbuilddir "/src",
LIBEXECDIR)))
goto error;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 2798010..404e90b 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1289,7 +1289,7 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
/* This helper is used to create custom leases file for libvirt */
if (!(leaseshelper_path = virFileFindResource("libvirt_leaseshelper",
- "src",
+ abs_topbuilddir "/src",
LIBEXECDIR)))
goto cleanup;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index d4fd658..76c1d0c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -887,7 +887,7 @@ doRemoteOpen(virConnectPtr conn,
if ((flags & VIR_DRV_OPEN_REMOTE_AUTOSTART) &&
!(daemonPath = virFileFindResourceFull("libvirtd",
NULL, NULL,
- "daemon",
+ abs_topbuilddir "/daemon",
SBINDIR,
"LIBVIRTD_PATH")))
goto failed;
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 9f4d76a..39082cc 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -301,7 +301,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
int ret;
if (!(parthelper_path = virFileFindResource("libvirt_parthelper",
- "src",
+ abs_topbuilddir "/src",
LIBEXECDIR)))
return -1;
@@ -346,7 +346,7 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
int ret;
if (!(parthelper_path = virFileFindResource("libvirt_parthelper",
- "src",
+ abs_topbuilddir "/src",
LIBEXECDIR)))
return -1;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 1b004d6..91dd0b8 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -248,7 +248,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags)
}
if (!(iohelper_path = virFileFindResource("libvirt_iohelper",
- "src",
+ abs_topbuilddir "/src",
LIBEXECDIR)))
goto error;
@@ -1618,7 +1618,8 @@ static bool useDirOverride;
* @filename: libvirt distributed filename without any path
* @prefix: optional string to prepend to filename
* @suffix: optional string to append to filename
- * @builddir: location of the binary in the source tree build tree
+ * @builddir: location of the filename in the build tree including
+ * abs_topsrcdir or abs_topbuilddir prefix
* @installdir: location of the installed binary
* @envname: environment variable used to override all dirs
*
@@ -1628,7 +1629,7 @@ static bool useDirOverride;
* path in the installed location.
*
* If @envname is non-NULL it will override all other
- * directory lookup
+ * directory lookup.
*
* Only use this with @filename files that are part of
* the libvirt tree, not 3rd party binaries/files.
@@ -1645,22 +1646,22 @@ virFileFindResourceFull(const char *filename,
{
char *ret = NULL;
const char *envval = envname ? virGetEnvBlockSUID(envname) : NULL;
+ const char *path;
if (!prefix)
prefix = "";
if (!suffix)
suffix = "";
- if (envval) {
- if (virAsprintf(&ret, "%s/%s%s%s", envval, prefix, filename,
suffix) < 0)
- return NULL;
- } else if (useDirOverride) {
- if (virAsprintf(&ret, "%s/%s/%s%s%s", abs_topbuilddir, builddir,
prefix, filename, suffix) < 0)
- return NULL;
- } else {
- if (virAsprintf(&ret, "%s/%s%s%s", installdir, prefix, filename,
suffix) < 0)
- return NULL;
- }
+ if (envval)
+ path = envval;
+ else if (useDirOverride)
+ path = builddir;
+ else
+ path = installdir;
+
+ if (virAsprintf(&ret, "%s/%s%s%s", path, prefix, filename, suffix) <
0)
+ return NULL;
VIR_DEBUG("Resolved '%s' to '%s'", filename, ret);
return ret;
@@ -1671,7 +1672,8 @@ virFileFindResource(const char *filename,
const char *builddir,
const char *installdir)
{
- return virFileFindResourceFull(filename, NULL, NULL, builddir, installdir, NULL);
+ return virFileFindResourceFull(filename, NULL, NULL, builddir,
+ installdir, NULL);
}
--
2.3.0