mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
util: activate directory override when used from library
The Perl bindings for libvirt use the test driver for unit tests. This tries to load the cpu_map/index.xml file, and when run from an uninstalled build will fail. The problem is that virFileActivateDirOverride is called by our various binaries like libvirtd, virsh, but is not called when a 3rd party app uses libvirt.so To deal with this we allow the LIBVIRT_DIR_OVERRIDE=1 env variable to be set and make virInitialize look for this. The 'run' script will set it, so now build using this script to run against an uninstalled tree we will correctly resolve files to the source tree. Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
29307fa84d
commit
b1b878c512
6
run.in
6
run.in
@ -60,6 +60,12 @@ else
|
||||
fi
|
||||
export PKG_CONFIG_PATH
|
||||
|
||||
# Ensure that any 3rd party apps using libvirt.so from the build tree get
|
||||
# files resolved to the build/source tree too. Typically useful for language
|
||||
# bindings running tests against non-installed libvirt.
|
||||
LIBVIRT_DIR_OVERRIDE=1
|
||||
export LIBVIRT_DIR_OVERRIDE
|
||||
|
||||
# This is a cheap way to find some use-after-free and uninitialized
|
||||
# read problems when using glibc.
|
||||
random_val="$(awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)"
|
||||
|
@ -247,6 +247,8 @@ virGlobalInit(void)
|
||||
virErrorInitialize() < 0)
|
||||
goto error;
|
||||
|
||||
virFileActivateDirOverrideForLib();
|
||||
|
||||
if (getuid() != geteuid() ||
|
||||
getgid() != getegid()) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
|
@ -1918,7 +1918,8 @@ virDirOpenQuiet;
|
||||
virDirRead;
|
||||
virFileAbsPath;
|
||||
virFileAccessibleAs;
|
||||
virFileActivateDirOverride;
|
||||
virFileActivateDirOverrideForLib;
|
||||
virFileActivateDirOverrideForProg;
|
||||
virFileBindMountDevice;
|
||||
virFileBuildPath;
|
||||
virFileCanonicalizePath;
|
||||
|
@ -1188,7 +1188,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
if (!(config = virLockDaemonConfigNew(privileged))) {
|
||||
VIR_ERROR(_("Can't create initial configuration"));
|
||||
|
@ -960,7 +960,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
if (!(config = virLogDaemonConfigNew(privileged))) {
|
||||
VIR_ERROR(_("Can't create initial configuration"));
|
||||
|
@ -1034,7 +1034,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
virUpdateSelfLastChanged(argv[0]);
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
while (1) {
|
||||
int optidx = 0;
|
||||
|
@ -1427,7 +1427,7 @@ main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
/* Initialize the log system */
|
||||
virLogSetFromEnv();
|
||||
|
@ -1774,7 +1774,7 @@ virFileFindResource(const char *filename,
|
||||
|
||||
|
||||
/**
|
||||
* virFileActivateDirOverride:
|
||||
* virFileActivateDirOverrideForProg:
|
||||
* @argv0: argv[0] of the calling program
|
||||
*
|
||||
* Look at @argv0 and try to detect if running from
|
||||
@ -1782,7 +1782,7 @@ virFileFindResource(const char *filename,
|
||||
* on the binary name, or '/.libs/' in the path
|
||||
*/
|
||||
void
|
||||
virFileActivateDirOverride(const char *argv0)
|
||||
virFileActivateDirOverrideForProg(const char *argv0)
|
||||
{
|
||||
char *file = strrchr(argv0, '/');
|
||||
if (!file || file[1] == '\0')
|
||||
@ -1796,6 +1796,20 @@ virFileActivateDirOverride(const char *argv0)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virFileActivateDirOverrideForLib:
|
||||
*
|
||||
* Look for LIBVIRT_DIR_OVERRIDE env var to see if we should find files from
|
||||
* the build/src tree instead of install tree.
|
||||
*/
|
||||
void
|
||||
virFileActivateDirOverrideForLib(void)
|
||||
{
|
||||
if (getenv("LIBVIRT_DIR_OVERRIDE") != NULL)
|
||||
useDirOverride = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virFileLength:
|
||||
* @path: full path of the file
|
||||
|
@ -193,8 +193,9 @@ char *virFileFindResourceFull(const char *filename,
|
||||
const char *installdir,
|
||||
const char *envname)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);
|
||||
void virFileActivateDirOverride(const char *argv0)
|
||||
void virFileActivateDirOverrideForProg(const char *argv0)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
void virFileActivateDirOverrideForLib(void);
|
||||
|
||||
off_t virFileLength(const char *path, int fd) ATTRIBUTE_NONNULL(1);
|
||||
bool virFileIsDir (const char *file) ATTRIBUTE_NONNULL(1);
|
||||
|
@ -992,7 +992,7 @@ int virTestMain(int argc,
|
||||
|
||||
setenv("VIR_TEST_MOCK_PROGNAME", progname, 1);
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
if (virTestSetEnvPath() < 0)
|
||||
return EXIT_AM_HARDFAIL;
|
||||
|
@ -897,7 +897,7 @@ main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
if (!vshInit(ctl, cmdGroups, NULL))
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1552,7 +1552,7 @@ main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
virFileActivateDirOverride(argv[0]);
|
||||
virFileActivateDirOverrideForProg(argv[0]);
|
||||
|
||||
if (!vshInit(ctl, cmdGroups, NULL))
|
||||
exit(EXIT_FAILURE);
|
||||
|
Loading…
Reference in New Issue
Block a user