Can I set up my own sub-environment?

Denys Vlasenko vda.linux at googlemail.com
Fri Feb 4 21:57:06 UTC 2011


On Friday 04 February 2011 12:32, Harald Becker wrote:
>  Hallo David!
> 
> > sub-environment?
> 
> Every process has its own environment. To set up your own environment
> just start a new process with an empty environment. From there you can
> add to your environment what you like/need.
> 
> > Is there any reason why that would upset 'standard' functions like
> > OpenVPN, PPP, dhcp or anything else, if I start them up from an
> > environment where they don't access the original /bin and friends? 
> Several programs use hard coded directories to access standard utilities
> and configuration files. You won't be able to change this by just adding
> something to your environment.
> 
> > at the start of S94netrix.... will everything invoked from it inherit
> > it....
>
> Child processes always inherit the environment of there parents. As this
> you do not need to set up your environment on every child invocation.
> Keep an eye on "ENV=", it only works with ash.

It is a standard feature of shells:

http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html

2.5.3 Shell Variables

Variables shall be initialized from the environment (as defined by the Base Definitions volume of IEEE Std 1003.1-2001, Chapter 8, Environment Variables and the exec function in the System Interfaces volume of IEEE Std 1003.1-2001) and can be given new values with variable assignment commands. If a variable is initialized from the environment, it shall be marked for export immediately; see the export special built-in. New variables can be defined and initialized with variable assignments, with the read or getopts utilities, with the name parameter in a for loop, with the ${ name= word} expansion, or with other mechanisms provided as implementation extensions.

The following variables shall affect the execution of the shell:

ENV
    [UP XSI] [Option Start] The processing of the ENV shell variable shall be supported on all XSI-conformant systems or if the system supports the User Portability Utilities option. [Option End]

    This variable, when and only when an interactive shell is invoked, shall be subjected to parameter expansion (see Parameter Expansion) by the shell and the resulting value shall be used as a pathname of a file containing shell commands to execute in the current environment. The file need not be executable. If the expanded value of ENV is not an absolute pathname, the results are unspecified. ENV shall be ignored if the user's real and effective user IDs or real and effective group IDs are different.

-- 
vda


More information about the busybox mailing list