Skip to content

Commit

Permalink
libredirect: workaround dyld env not inherited
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Nov 5, 2021
1 parent d1a3b5c commit 7acc0e0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkgs/build-support/libredirect/libredirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down

0 comments on commit 7acc0e0

Please sign in to comment.