Skip to content

Commit

Permalink
main.c: append previously existing LD_PRELOAD contents rather than ov…
Browse files Browse the repository at this point in the history
…erwriting

some broken programs like pulseaudio rely on LD_PRELOAD hacks to function,
if we just override the environment variable, those will stop working.

simplified version of patch suggested by @hexchain

closes rofl0r#35
  • Loading branch information
rofl0r committed Jul 9, 2014
1 parent 84d9a97 commit ed7c890
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,20 @@ int main(int argc, char *argv[]) {
#ifdef IS_MAC
putenv("DYLD_FORCE_FLAT_NAMESPACE=1");
#define LD_PRELOAD_ENV "DYLD_INSERT_LIBRARIES"
#define LD_PRELOAD_SEP ":"
#else
#define LD_PRELOAD_ENV "LD_PRELOAD"
/* all historic implementations of BSD and linux dynlinkers seem to support
space as LD_PRELOAD separator, with colon added only recently.
we use the old syntax for maximum compat */
#define LD_PRELOAD_SEP " "
#endif
snprintf(buf, sizeof(buf), LD_PRELOAD_ENV "=%s/%s", prefix, dll_name);
char *old_val = getenv(LD_PRELOAD_ENV);
snprintf(buf, sizeof(buf), LD_PRELOAD_ENV "=%s/%s%s%s",
prefix, dll_name,
/* append previous LD_PRELOAD content, if existent */
old_val ? LD_PRELOAD_SEP : "",
old_val ? old_val : "");
putenv(buf);
execvp(argv[start_argv], &argv[start_argv]);
perror("proxychains can't load process....");
Expand Down

0 comments on commit ed7c890

Please sign in to comment.