Respect HOME environment variable if set
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
committed by
John Hood
parent
9019f62bf6
commit
b604a7d7c2
@@ -776,17 +776,21 @@ static void print_motd( void )
|
|||||||
|
|
||||||
static void chdir_homedir( void )
|
static void chdir_homedir( void )
|
||||||
{
|
{
|
||||||
|
const char *home = getenv( "HOME" );
|
||||||
|
if ( home == NULL ) {
|
||||||
struct passwd *pw = getpwuid( geteuid() );
|
struct passwd *pw = getpwuid( geteuid() );
|
||||||
if ( pw == NULL ) {
|
if ( pw == NULL ) {
|
||||||
perror( "getpwuid" );
|
perror( "getpwuid" );
|
||||||
return; /* non-fatal */
|
return; /* non-fatal */
|
||||||
}
|
}
|
||||||
|
home = pw->pw_dir;
|
||||||
|
}
|
||||||
|
|
||||||
if ( chdir( pw->pw_dir ) < 0 ) {
|
if ( chdir( home ) < 0 ) {
|
||||||
perror( "chdir" );
|
perror( "chdir" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( setenv( "PWD", pw->pw_dir, 1 ) < 0 ) {
|
if ( setenv( "PWD", home, 1 ) < 0 ) {
|
||||||
perror( "setenv" );
|
perror( "setenv" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user