Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Apr 2008 20:18:20 -0700
From:      Doug Hardie <bc979@lafn.org>
To:        Jeremy Chadwick <koitsu@freebsd.org>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: getenv in FreeBSD 7
Message-ID:  <48EED2B2-CB92-4907-A70B-9E86566F4EF3@lafn.org>
In-Reply-To: <20080407005444.GB77472@eos.sc1.parodius.com>
References:  <1794897B-7A36-412A-8849-87F10268EBAE@lafn.org> <20080406214524.GA72199@eos.sc1.parodius.com> <20080406215237.GA72336@eos.sc1.parodius.com> <C5E057AC-1533-4EE8-B678-339B7EC97FA6@lafn.org> <20080407005444.GB77472@eos.sc1.parodius.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Apr 6, 2008, at 17:54, Jeremy Chadwick wrote:
> On Sun, Apr 06, 2008 at 03:05:18PM -0700, Doug Hardie wrote:
>>
>> On Apr 6, 2008, at 14:52, Jeremy Chadwick wrote:
>>> On Sun, Apr 06, 2008 at 02:45:24PM -0700, Jeremy Chadwick wrote:
>>>> On Sun, Apr 06, 2008 at 02:37:06PM -0700, Doug Hardie wrote:
>>>>> Somewhere between FreeBSD 6.2 and 7.0 getenv has been changed to  
>>>>> return
>>>>> a
>>>>> null if an environment variable is set but has no value.  I  
>>>>> don't find
>>>>> anything anywhere in the documentation/man pages on this.  As a  
>>>>> result,
>>>>> you
>>>>> cannot distinguish between a variable that is not set and one  
>>>>> that is
>>>>> set
>>>>> to a value of "".  Is this a bug or a feature change?
>>>>
>>>> I'd begin peeking here:
>>>>
>>>> http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdlib/getenv.c
>>>
>>> Follow-up: the manpages between 6.3-PRERELEASE and 7.0-STABLE do
>>> document said change:
>>>
>>> http://www.freebsd.org/cgi/man.cgi?query=getenv&apropos=0&sektion=3&manpath=FreeBSD+6.3-RELEASE&format=html
>>
>> Says that if the environment variable is NOT IN THE ENVIRONMENT  
>> then null
>> is returned.  Setting the variable to "" does put it in the  
>> environment.
>> env returns it properly.
>>
>>>
>>>
>>> http://www.freebsd.org/cgi/man.cgi?query=getenv&apropos=0&sektion=3&manpath=FreeBSD+7.0-stable&format=html
>>
>> Same thing.  I find nothing documented about this change.
>
> I'm not sure where you're going with this.  I see it clearly in the
> ERRORS section.

I didn't think that having a defined variable with the value "" would  
be an error.  getenv does not return EINVAL but returns a zero.  I  
would have expected some notification in the description of getenv.

>
>
> But besides that, just like Bakul Shah, I cannot reproduce this  
> problem:
>
> $ uname -mr
> 7.0-STABLE amd64
> $ gcc -o z z.c
> $ ./z
> getenv(FOO) = (null)
> $ export FOO=yep
> $ ./z
> getenv(FOO) = yep
> export FOO=
> $ ./z
> getenv(FOO) =
> $ cat z.c
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
>  char *e = getenv("FOO");
>
>  printf("getenv(FOO) = %s\n", e);
>  return 0;
> }

At this time, it does return a pointer to "".  However, earlier today  
it did not.  It returned a zero.  It was quite consistent for several  
hours.  I wonder if this is another issue with gdb.  It seems to be  
quite flakey on 7.0.

>
>
> Finally, why did you take freebsd-stable off this mail  
> conversation?  If
> others have the same question in the future, they're not going to be
> able to read what partook here.  I'm re-adding the list.

Thought I did include it.  Must have used reply instead of reply all.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48EED2B2-CB92-4907-A70B-9E86566F4EF3>