bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I am not even remotely sure whether this is a bug: redefining getenv


From: Chet Ramey
Subject: Re: I am not even remotely sure whether this is a bug: redefining getenv/setenv/et al.
Date: Sat, 12 Mar 2016 14:11:06 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

On 3/10/16 3:48 PM, Peter Seebach wrote:

> And I have for some time had a very strange problem, which is that
> "sometimes" unsetting LD_PRELOAD doesn't work. Well, it turns out that the
> issue is that bash provides its own definitions of getenv/setenv/unsetenv,
> and they don't automatically modify environ.
> 
> It seems pretty obvious to me that there are Sound Technical Reasons for the
> shell to wish to maintain an "environment" which is not actually stored in
> environ, so that part makes sense.
> 

Bash maintains a set of variables, some of which have the export attribute.
Those become the environment for processes that bash execs.  Plenty of libc
functions use the getenv/setenv interface to modify their behavior.  So
far, so good.

Users expect the changes they make to exported shell variables to be
reflected in the bash behavior.  TZ (tzset) and the LC_ variables
(setlocale) are examples; I'm sure there are others I don't mention.

Bash redefines getenv/setenv (where possible) to allow libc functions that
use those interfaces to retrieve current values of the exported shell
variables.  Bash lazily updates environ when it needs to create the export
environment for a new child process, and makes it point to the list of
exported variables it passes to execve().

There is no need to create functions like bash_getenv and bash_setenv; bash
already has its own internal interfaces to set variable values and
attributes and to retrieve them.

It's true that modifying the value of environ crosses into Posix undefined
behavior.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]