Environment variables set by /env/bin/init disappear when script exits

Ian Abbott abbotti at mev.co.uk
Tue Jun 11 08:21:06 PDT 2019

On 11/06/2019 15:52, Ian Abbott wrote:
> Since commit 90df2a955e3c ("defaultenv: Convert init script to C"), if 
> the legacy /env/bin/init script is still being used, any environment 
> variables that were set in the script (such as the PS1 prompt) disappear 
> when the script exits.  I guess it is because the script is now run 
> directly by run_command(initfile) (initfile is "/env/bin/init") rather 
> than by run_command("source /env/bin/init").

This seems easy to fix in "common/startup.c", assuming it is indeed a 
bug.  Which of the following fixes would be preferable?

1. Call run_command with a string literal:

     run_command("source /env/bin/init");

2. Call run_command with a string constant:

     const char *source_initfile = "source /env/bin/init";


3. Call run_command with a dynamically constructed string:

     char *scr;

     scr = basprintf("source %s", initfile);

-=( Ian Abbott <abbotti at mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-

More information about the barebox mailing list