From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 24 15:18:11 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 E81001065677 for ; Fri, 24 Aug 2012 15:18:11 +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 B523C8FC0A for ; Fri, 24 Aug 2012 15:18:11 +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 q7OFI3Z9012108 for ; Fri, 24 Aug 2012 09:18:03 -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 q7OFHMAT043936; Fri, 24 Aug 2012 09:17:22 -0600 (MDT) (envelope-from jhein@gromit.timing.com) Received: (from jhein@localhost) by gromit.timing.com (8.14.5/8.14.5/Submit) id q7OFHMnS043935; Fri, 24 Aug 2012 09:17:22 -0600 (MDT) (envelope-from jhein) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <20535.39682.330250.337503@gromit.timing.com> Date: Fri, 24 Aug 2012 09:17:22 -0600 From: John Hein To: hackers@freebsd.org X-Mailer: VM 8.2.0b-trunk-1408 under 23.4.1 (i386-portbld-freebsd7.4) Cc: Subject: 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:18:12 -0000 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 6.x & 4.x ... % sh -c 'XXX=1 LD_PRELOAD=$(pwd)/sl.so 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.