diff --git a/src/Makefile.am b/src/Makefile.am index b41c6d4236..a938d7ea7f 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 b13cae87e1..2e352934ca 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 b77f68847e..6130f8a530 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 1be32efbee..db03438ba3 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 18bd359739..5d80fc23fc 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 2af3f22410..8d184fec9a 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 ec90d04176..f277f22cba 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 b6d1797284..d1a3be551c 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 2798010c4f..404e90b639 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 d4fd658089..76c1d0c2d1 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 9f4d76a9b3..39082cc5bd 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 1b004d69b8..c528a1c01a 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;