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.
*/
extern wchar_t *program_name;
/**
Take an array_list_t containing wide strings and converts them to a wchar_t **.
*/

51
env.c
View file

@ -258,7 +258,7 @@ void env_init()
{
char **p;
struct passwd *pw;
wchar_t *uname;
wchar_t *uname, *path;
sb_init( &dyn_var );
@ -318,6 +318,7 @@ void env_init()
val = wcschr( key, L'=' );
if( val == 0 )
env_set( key, L"", ENV_EXPORT );
else
@ -338,6 +339,54 @@ void env_init()
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() );
uname = str2wcs( pw->pw_name );
env_set( L"USER", uname, ENV_GLOBAL | ENV_EXPORT );

View file

@ -7,8 +7,7 @@
# 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
@ -18,14 +17,12 @@ set IFS \ \t\n
for i in /bin /usr/bin /usr/X11R6/bin @PREFIX@/bin
if test -d $i
if echo $PATH|grep $i >/dev/null
else
if not echo $PATH|grep $i >/dev/null
set PATH $PATH $i
end
end
end
#
# Set some value for LANG if nothing was set before
#