]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Preload mocks with DYLD_INSERT_LIBRARIES on macOS
authorRoman Bolshakov <r.bolshakov@yadro.com>
Wed, 21 Aug 2019 16:13:15 +0000 (19:13 +0300)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 23 Aug 2019 10:26:26 +0000 (11:26 +0100)
LD_PRELOAD has no effect on macOS. Instead, dyld(1) provides a way for
symbol hooking via DYLD_INSERT_LIBRARIES. The variable should contain
colon-separated paths to the dylibs to be inserted.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
tests/testutils.h

index 8c12fd7c12bf9ad6ad7343dbec02982aa74de935..07dda6e355c1ebc7a7dbc8a72ab9ecef7d4984be 100644 (file)
@@ -117,9 +117,15 @@ int virTestMain(int argc,
         return virTestMain(argc, argv, func, NULL); \
     }
 
+#ifdef __APPLE__
+# define PRELOAD_VAR "DYLD_INSERT_LIBRARIES"
+#else
+# define PRELOAD_VAR "LD_PRELOAD"
+#endif
+
 #define VIR_TEST_PRELOAD(lib) \
     do { \
-        const char *preload = getenv("LD_PRELOAD"); \
+        const char *preload = getenv(PRELOAD_VAR); \
         if (preload == NULL || strstr(preload, lib) == NULL) { \
             char *newenv; \
             if (!virFileIsExecutable(lib)) { \
@@ -132,7 +138,7 @@ int virTestMain(int argc,
                 perror("virAsprintf"); \
                 return EXIT_FAILURE; \
             } \
-            setenv("LD_PRELOAD", newenv, 1); \
+            setenv(PRELOAD_VAR, newenv, 1); \
             execv(argv[0], argv); \
         } \
     } while (0)