From 7acc0e054c5d64de945e69a17c57e33410d04f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Thu, 4 Nov 2021 21:14:12 +0100 Subject: [PATCH] libredirect: workaround dyld env not inherited --- pkgs/build-support/libredirect/libredirect.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index 46bab07b91db..7dac4684722f 100644 --- a/pkgs/build-support/libredirect/libredirect.c +++ b/pkgs/build-support/libredirect/libredirect.c @@ -308,7 +308,20 @@ static char * replace_string(char * buf, char * from, char * to) { } static void rewriteSystemCall(const char * command, char * buf) { - strcpy(buf, command); + char * p = buf; + + #ifdef __APPLE__ + // The dyld environment variable is not inherited by the subprocess spawned + // by system(), so this hack redefines it. + Dl_info info; + dladdr(&rewriteSystemCall, &info); + p = stpcpy(p, "export DYLD_INSERT_LIBRARIES="); + p = stpcpy(p, info.dli_fname); + p = stpcpy(p, ";"); + #endif + + stpcpy(p, command); + for (int n = 0; n < nrRedirects; ++n) { replace_string(buf, from[n], to[n]); }