libredirect: workaround dyld env not inherited

This commit is contained in:
Stéphan Kochen 2021-11-04 21:14:12 +01:00
parent d1a3b5c4cc
commit 7acc0e054c

View file

@ -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]);
}