提交 351492e3 编写于 作者: R Roman Bolshakov 提交者: Daniel P. Berrangé

tests: Preload mocks with DYLD_INSERT_LIBRARIES on macOS

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: NRoman Bolshakov <r.bolshakov@yadro.com>
上级 dbb5e20e
...@@ -117,9 +117,15 @@ int virTestMain(int argc, ...@@ -117,9 +117,15 @@ int virTestMain(int argc,
return virTestMain(argc, argv, func, NULL); \ 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) \ #define VIR_TEST_PRELOAD(lib) \
do { \ do { \
const char *preload = getenv("LD_PRELOAD"); \ const char *preload = getenv(PRELOAD_VAR); \
if (preload == NULL || strstr(preload, lib) == NULL) { \ if (preload == NULL || strstr(preload, lib) == NULL) { \
char *newenv; \ char *newenv; \
if (!virFileIsExecutable(lib)) { \ if (!virFileIsExecutable(lib)) { \
...@@ -132,7 +138,7 @@ int virTestMain(int argc, ...@@ -132,7 +138,7 @@ int virTestMain(int argc,
perror("virAsprintf"); \ perror("virAsprintf"); \
return EXIT_FAILURE; \ return EXIT_FAILURE; \
} \ } \
setenv("LD_PRELOAD", newenv, 1); \ setenv(PRELOAD_VAR, newenv, 1); \
execv(argv[0], argv); \ execv(argv[0], argv); \
} \ } \
} while (0) } while (0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册