* Do not clobber LD_PRELOAD, patch by Sami Liedes. Heavily rewritten.

This commit is contained in:
Sam Hocevar 2007-07-09 23:51:49 +00:00 committed by sam
parent cc7dc895b5
commit 5faa15e62d
2 changed files with 24 additions and 8 deletions

View File

@ -7,4 +7,4 @@ other contributors:
Rémi Denis-Courmont <rdenis#simphalempin:com> (readv, recvmsg)
Clément Stenac <zorglub#diwi:org> (pread)
Dominik Kuhlen <dominik.kuhlen#gmit-gmbh:de> (recvfrom)
Sami Liedes <sliedes#cc:hut:fi> (LD_PRELOAD conservation)

View File

@ -909,18 +909,34 @@ static int run_process(struct opts *opts, int pipes[][2])
setenv("ZZUF_MAXRATIO", buf, 1);
#if defined HAVE_FORK
libpath = malloc(len + strlen("/.libs/" FILENAME EXTRAINFO) + 1);
/* Meaningless but makes sure there is space for everything */
libpath = malloc(len + strlen(LIBDIR "/.libs/" FILENAME EXTRAINFO) + 1);
strcpy(libpath, opts->oldargv[0]);
/* Replace "/path/binaryname" with "/path/.libs/libzzuf.$(EXT)"
* and "binaryname" with ".libs/libzzuf.$(EXT)"
* Write the result in libpath. */
tmp = strrchr(libpath, '/');
strcpy(tmp ? tmp + 1 : libpath, ".libs/" FILENAME);
ret = access(libpath, R_OK);
strcpy(tmp ? tmp + 1 : libpath, ".libs/" FILENAME EXTRAINFO);
if(ret == 0)
setenv(PRELOAD, libpath, 1);
else
setenv(PRELOAD, LIBDIR "/" FILENAME EXTRAINFO, 1);
ret = access(libpath, R_OK);
if(ret < 0)
strcpy(libpath, LIBDIR "/" FILENAME);
/* OSF1 only */
strcat(libpath, EXTRAINFO);
/* Do not clobber previous LD_PRELOAD values */
tmp = getenv(PRELOAD);
if(tmp && *tmp)
{
char *bigbuf = malloc(strlen(tmp) + strlen(libpath) + 2);
sprintf(bigbuf, "%s:%s", tmp, libpath);
free(libpath);
libpath = bigbuf;
}
setenv(PRELOAD, libpath, 1);
free(libpath);
if(execvp(opts->newargv[0], opts->newargv))