Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Dec 2009 12:24:30 -0500
From:      Brian Fundakowski Feldman <green@FreeBSD.org>
To:        "Sean C. Farley" <scf@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r199983 - in head: lib/libc/stdlib tools/regression/environ
Message-ID:  <20091201172430.GD35660@green.homeunix.org>
In-Reply-To: <alpine.BSF.2.00.0912010953220.68765@thor.farley.org>
References:  <200912010504.nB154VnS053167@svn.freebsd.org> <alpine.BSF.2.00.0912010953220.68765@thor.farley.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 01, 2009 at 10:01:59AM -0600, Sean C. Farley wrote:
> On Tue, 1 Dec 2009, Brian Feldman wrote:
> 
>>  I also fixed another inconsistency in getenv(3) where updating the
>>  global environ pointer would not be reflected in the return values.
>>  It would have taken an intermediary setenv(3)/putenv(3)/unsetenv(3)
>>  in order to see the change.
> 
> In the current code, if environ is replaced or none of the set/put/unset 
> calls have been made, getenv() will use __findenv_environ() (searches 
> environ directly) to find the entry.  This is necessary since malloc() 
> depends upon getenv() creating a cross-dependency.

Could you replace the (quoted) comment wholesale with something to that effect?

>> @@ -426,22 +439,18 @@ getenv(const char *name)
>> 	}
>> 
>> 	/*
>> -	 * An empty environment (environ or its first value) regardless if
>> -	 * environ has been copied before will return a NULL.
>> -	 *
>> -	 * If the environment is not empty, find an environment variable via
>> -	 * environ if environ has not been copied via an *env() call or been
>> -	 * replaced by a running program, otherwise, use the rebuilt
>> -	 * environment.
>> +	 * If we have not already allocated memory by performing
>> +	 * write operations on the environment, avoid doing so now.
>> 	 */
>> -	if (environ == NULL || environ[0] == NULL)
>> -		return (NULL);
>> -	else if (envVars == NULL || environ != intEnviron)
>> +	if (envVars == NULL)
>> 		return (__findenv_environ(name, nameLen));
>> -	else {
>> -		envNdx = envVarsTotal - 1;
>> -		return (__findenv(name, nameLen, &envNdx, true));
>> -	}
>> +
>> +	/* Synchronize environment. */
>> +	if (__merge_environ() == -1)
>> +		return (NULL);
>> +
>> +	envNdx = envVarsTotal - 1;
>> +	return (__findenv(name, nameLen, &envNdx, true));
>> }

-- 
Brian Fundakowski Feldman                           \'[ FreeBSD ]''''''''''\
  <> green@FreeBSD.org                               \  The Power to Serve! \
 Opinions expressed are my own.                       \,,,,,,,,,,,,,,,,,,,,,,\



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