LD_PRELOADed code before or after exec - different behavior
after 6.x
John Hein
jhein at symmetricom.com
Fri Aug 24 15:38:46 UTC 2012
John Hein wrote at 09:34 -0600 on Aug 24, 2012:
> John Hein wrote at 09:17 -0600 on Aug 24, 2012:
> >
> > head sl.cc pe.c
> > ==> sl.cc <==
> > #include <cstdio>
> > #include <cstdlib>
> > class C
> > {
> > public:
> > C(){
> > printf("C\n");
> > unsetenv("XXX");
> > }
> > };
> > static C c;
> >
> > ==> pe.c <==
> > #include <stdio.h>
> > #include <stdlib.h>
> > int
> > main()
> > {
> > char *p=getenv("XXX");
> > if (p != NULL)
> > printf("XXX=%s\n",p);
> > return 0;
> > }
> >
> >
> > % g++ -fpic -shared sl.cc -o sl.so
> > % gcc pe.c -o pe
> >
> > 7.x & 8.x ...
> > % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
> > C
> > XXX=1
>
> I meant to write:
>
> 7.x & 8.x ...
> % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
> C
> % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so exec pe'
> C
> XXX=1
>
> > 6.x & 4.x ...
> > % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
> > C
>
> and
> 6.x & 4.x ...
> % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
> C
> % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so exec pe'
> C
Argh. Never mind. I was correct the first time. The shell's exec
doesn't matter...
7.x & 8.x ...
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
C
XXX=1
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so exec pe'
C
XXX=1
6.x & 4.x ...
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so pe'
C
% sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so exec pe'
C
> > In 6.x and earlier (fedora 16, too), the unsetenv clears the XXX env
> > var apparently in time to affect the exec'd process. In 8.x & 9.x, it
> > seems the environment is set and passed to the exec'd process and the
> > LD_PRELOADed code does not affect that despite its best efforts.
> >
> > It seems to me that 6.x behavior is more correct, but I'm seeking
> > opinions before contemplating if / how to put together a fix.
> >
More information about the freebsd-hackers
mailing list