Make sure PATH contains vital directories during init

darcs-hash:20051025093945-ac50b-8939b844e472caf43a206e2a0dbfa0d48ffdd45c.gz
This commit is contained in:
axel 2005-10-25 19:39:45 +10:00
parent 48afe8062e
commit d332293245
4 changed files with 56 additions and 9 deletions

View file

@ -67,6 +67,7 @@ extern char *profile;
debug function. debug function.
*/ */
extern wchar_t *program_name; extern wchar_t *program_name;
/** /**
Take an array_list_t containing wide strings and converts them to a wchar_t **. Take an array_list_t containing wide strings and converts them to a wchar_t **.
*/ */

55
env.c
View file

@ -258,7 +258,7 @@ void env_init()
{ {
char **p; char **p;
struct passwd *pw; struct passwd *pw;
wchar_t *uname; wchar_t *uname, *path;
sb_init( &dyn_var ); sb_init( &dyn_var );
@ -312,12 +312,13 @@ void env_init()
wchar_t *pos; wchar_t *pos;
key = str2wcs(*p); key = str2wcs(*p);
if( !key ) if( !key )
continue; continue;
val = wcschr( key, L'=' ); val = wcschr( key, L'=' );
if( val == 0 ) if( val == 0 )
env_set( key, L"", ENV_EXPORT ); env_set( key, L"", ENV_EXPORT );
else else
@ -332,11 +333,59 @@ void env_init()
*pos = ARRAY_SEP; *pos = ARRAY_SEP;
pos++; pos++;
} }
env_set( key, val, ENV_EXPORT | ENV_GLOBAL ); env_set( key, val, ENV_EXPORT | ENV_GLOBAL );
} }
free(key); free(key);
} }
path = env_get( L"PATH" );
if( !path )
{
env_set( L"PATH", L"/bin" ARRAY_SEP_STR L"/usr/bin", ENV_EXPORT | ENV_GLOBAL );
}
else
{
int i;
array_list_t l;
int has_bin=0, has_usr_bin=0;
al_init( &l );
expand_variable_array( path, &l );
for( i=0; i<al_get_count( &l); i++ )
{
wchar_t * el = (wchar_t *)al_get( &l, i );
if( contains_str( el, L"/bin", L"/bin/", (void *)0) )
{
has_bin = 1;
}
if( contains_str( el, L"/usr/bin", L"/usr/bin/", (void *)0) )
{
has_bin = 1;
}
}
if( !( has_bin && has_usr_bin ) )
{
string_buffer_t b;
sb_init( &b );
sb_append( &b, path );
if( !has_bin )
sb_append( &b, ARRAY_SEP_STR L"/bin" );
if( !has_usr_bin )
sb_append( &b, ARRAY_SEP_STR L"/usr/bin" );
env_set( L"PATH", (wchar_t *)b.buff, ENV_GLOBAL | ENV_EXPORT );
sb_destroy( &b );
}
al_foreach( &l, (void (*)(const void *))&free );
al_destroy( &l );
}
pw = getpwuid( getuid() ); pw = getpwuid( getuid() );
uname = str2wcs( pw->pw_name ); uname = str2wcs( pw->pw_name );

View file

@ -7,8 +7,7 @@
# Set default field separators # Set default field separators
# #
set IFS \ \t\n set -g IFS \ \t\n
# #
# Add a few common directories to path, if they exists. Note that pure # Add a few common directories to path, if they exists. Note that pure
@ -18,14 +17,12 @@ set IFS \ \t\n
for i in /bin /usr/bin /usr/X11R6/bin @PREFIX@/bin for i in /bin /usr/bin /usr/X11R6/bin @PREFIX@/bin
if test -d $i if test -d $i
if echo $PATH|grep $i >/dev/null if not echo $PATH|grep $i >/dev/null
else
set PATH $PATH $i set PATH $PATH $i
end end
end end
end end
# #
# Set some value for LANG if nothing was set before # Set some value for LANG if nothing was set before
# #

2
main.c
View file

@ -217,7 +217,7 @@ int main( int argc, char **argv )
function_init(); function_init();
env_init(); env_init();
complete_init(); complete_init();
reader_init(); reader_init();
reader_push_current_filename( L"(internal)" ); reader_push_current_filename( L"(internal)" );