tests: mock: Accept spaces in build path

If path to the build directory contains spaces (e.g. meson setup
'a b') then our mocks don't work. The problem is in glibc where
not just a colon but also a space character is a delimiter for
LD_PRELOAD [1]. Hence, a test using mock tries to preload
something like libvirt.git/a b/libsomethingmock.so which is
interpreted by glibc as two separate strings: "libvirt.git/a",
"b/libsomethingmock.so".

One trick to get around this is to set LD_PRELOAD to just the
shared object file (without path) and let glibc find the mock in
paths specified in LD_LIBRARY_PATH (where only a colon or a
semicolon are valid separators [1]). This can be seen in action
by running say:

  LD_DEBUG=libs ./virpcitest

1: https://man7.org/linux/man-pages/man8/ld.so.8.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik committed 2024-04-15 09:24:16 +02:00
1 parent ece476ec2e
commit eac646ea49
5 files changed
+18 -6

No files matched your search

+4 -2
View File
@@ -837,8 +837,10 @@ int virTestMain(int argc,
va_start(ap, func);
while ((lib = va_arg(ap, const char *))) {
if (!virFileIsExecutable(lib)) {
perror(lib);
g_autofree char *abs_lib_path = g_strdup_printf("%s/%s", abs_builddir, lib);
if (!virFileIsExecutable(abs_lib_path)) {
perror(abs_lib_path);
va_end(ap);
return EXIT_FAILURE;
}