Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 May 2013 16:21:52 +0200
From:      Thomas Mueller <tmueller@sysgo.com>
To:        David Wolfskill <david@catwhisker.org>
Cc:        freebsd-ports@freebsd.org
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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=<value optimized out>, argv=<value optimized out>, environ=<value optimized out>)
     at twm.c:254
 (gdb) frame 1
 #1  0x000000000040b397 in main (argc=<value optimized out>, argv=<value optimized out>, environ=<value optimized out>)
     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 <Error reading address 0xffffffffffffdf3a: Bad address>
 =========

Similarly,
   twm.c:306: warning: incompatible implicit declaration of built-in function 'calloc'
including <stdlib.h> provides a proper declaration for calloc().

-- 
Thomas Mueller



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130527162152.5c400069>