From owner-freebsd-ports@FreeBSD.ORG Mon May 27 14:22:03 2013 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A0D4E128 for ; Mon, 27 May 2013 14:22:03 +0000 (UTC) (envelope-from tmueller@sysgo.com) Received: from mail1.sysgo.com (mail1.sysgo.com [176.9.26.183]) by mx1.freebsd.org (Postfix) with ESMTP id 632806E9 for ; Mon, 27 May 2013 14:22:03 +0000 (UTC) Received: from lantia.sysgo.com (unknown [172.22.2.7]) by mail1.sysgo.com (Postfix) with ESMTP id 65DAE46182; Mon, 27 May 2013 16:21:53 +0200 (CEST) Received: by lantia.sysgo.com (Postfix, from userid 113) id EAAB54EE002; Mon, 27 May 2013 16:21:52 +0200 (CEST) Received: from tmu.ulm.sysgo.com (tmu.ulm.sysgo.com [172.30.3.10]) by lantia.sysgo.com (Postfix) with ESMTP id 225444EE001; Mon, 27 May 2013 16:21:52 +0200 (CEST) Date: Mon, 27 May 2013 16:21:52 +0200 From: Thomas Mueller To: David Wolfskill Subject: Re: Proper way to access executable's "environment"? Message-ID: <20130527162152.5c400069@tmu.ulm.sysgo.com> In-Reply-To: <20130526180629.GB1334@albert.catwhisker.org> References: <20130526172015.GA1334@albert.catwhisker.org> <51A24C77.6000108@gmx.net> <20130526180629.GB1334@albert.catwhisker.org> Organization: SYSGO AG X-Mailer: Claws Mail 3.9.1 (GTK+ 2.24.18; amd64-portbld-freebsd9.1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-ports@freebsd.org X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 May 2013 14:22:03 -0000 On Sun, 26 May 2013 11:06:29 -0700, David Wolfskill wrote: > On Sun, May 26, 2013 at 07:55:03PM +0200, Stefan Ehmann wrote: > > ... > > > So I have a couple of questions related to the above: > > > * Is the patch correct?... > > > > Should be fine. See environ(7) or > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/environ.html: > > > > "In addition, the following variable, which must be declared by the user > > if it is to be used directly: extern char **environ; " > > Cool; thanks. > > (Aside: I'd be happy to hear of plausible reasons the earlier approach > does not appear to fail in i386. I'm suspecting some sort of > compatibilty shim -- which was jettisoned for amd64, probably quite > intentionally.) On AMD64 sizeof(void *)!=sizeof(int), thus warnings such as twm.c:250: warning: assignment makes pointer from integer without a cast should trigger alarms. ======= GDB session Program received signal SIGSEGV, Segmentation fault. 0x0000000801b60697 in strlen () from /lib/libc.so.7 (gdb) bt #0 0x0000000801b60697 in strlen () from /lib/libc.so.7 #1 0x000000000040b397 in main (argc=, argv=, environ=) at twm.c:254 (gdb) frame 1 #1 0x000000000040b397 in main (argc=, argv=, environ=) at twm.c:254 254 HomeLen = strlen(Home); (gdb) l 249 250 Home = getenv("HOME"); 251 if (Home == NULL) 252 Home = "./"; 253 254 HomeLen = strlen(Home); (gdb) p Home $1 = 0xffffffffffffdf3a ========= Similarly, twm.c:306: warning: incompatible implicit declaration of built-in function 'calloc' including provides a proper declaration for calloc(). -- Thomas Mueller