From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 24 15:35:05 2012 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1FFFF1065675 for ; Fri, 24 Aug 2012 15:35:05 +0000 (UTC) (envelope-from jhein@symmetricom.com) Received: from duck.symmetricom.us (duck.symmetricom.us [206.168.13.214]) by mx1.freebsd.org (Postfix) with ESMTP id DC24A8FC1C for ; Fri, 24 Aug 2012 15:35:04 +0000 (UTC) Received: from gromit.timing.com (gromit.timing.com [206.168.13.209]) by duck.symmetricom.us (8.14.5/8.14.5) with ESMTP id q7OFZ4jB012430 for ; Fri, 24 Aug 2012 09:35:04 -0600 (MDT) (envelope-from jhein@symmetricom.com) Received: from gromit.timing.com (localhost [127.0.0.1]) by gromit.timing.com (8.14.5/8.14.5) with ESMTP id q7OFYZwv044196; Fri, 24 Aug 2012 09:34:35 -0600 (MDT) (envelope-from jhein@gromit.timing.com) Received: (from jhein@localhost) by gromit.timing.com (8.14.5/8.14.5/Submit) id q7OFYT6c044195; Fri, 24 Aug 2012 09:34:29 -0600 (MDT) (envelope-from jhein) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <20535.40709.486888.887048@gromit.timing.com> Date: Fri, 24 Aug 2012 09:34:29 -0600 From: John Hein To: hackers@freebsd.org In-Reply-To: <20535.39682.330250.337503@gromit.timing.com> References: <20535.39682.330250.337503@gromit.timing.com> X-Mailer: VM 8.2.0b-trunk-1408 under 23.4.1 (i386-portbld-freebsd7.4) Cc: Subject: Re: LD_PRELOADed code before or after exec - different behavior after 6.x X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Aug 2012 15:35:05 -0000 John Hein wrote at 09:17 -0600 on Aug 24, 2012: > > head sl.cc pe.c > ==> sl.cc <== > #include > #include > class C > { > public: > C(){ > printf("C\n"); > unsetenv("XXX"); > } > }; > static C c; > > ==> pe.c <== > #include > #include > 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 > 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. >