Skip to content

Commit

Permalink
termemu: respect $SHELL and exec argv if given
Browse files Browse the repository at this point in the history
Signed-off-by: John Hood <cgull@glup.org>
  • Loading branch information
cgull committed Jun 6, 2015
1 parent 73fd644 commit 8a91e78
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/examples/termemu.cc
Expand Up @@ -72,7 +72,7 @@ const size_t buf_size = 16384;

static void emulate_terminal( int fd );

int main( void )
int main( int argc, char *argv[] )
{
int master;
struct termios saved_termios, raw_termios, child_termios;
Expand Down Expand Up @@ -116,19 +116,26 @@ int main( void )
exit( 1 );
}

/* get shell name */
struct passwd *pw = getpwuid( geteuid() );
if ( pw == NULL ) {
perror( "getpwuid" );
exit( 1 );
}

char *my_argv[ 2 ];
my_argv[ 0 ] = strdup( pw->pw_shell );
assert( my_argv[ 0 ] );
my_argv[ 1 ] = NULL;

if ( execv( pw->pw_shell, my_argv ) < 0 ) {
if ( argc > 1 ) {
argv++;
} else {
/* get shell name */
my_argv[ 0 ] = getenv( "SHELL" );
if ( my_argv[ 0 ] == NULL ) {
struct passwd *pw = getpwuid( geteuid() );
if ( pw == NULL ) {
perror( "getpwuid" );
exit( 1 );
}
my_argv[ 0 ] = strdup( pw->pw_shell );
}
assert( my_argv[ 0 ] );
my_argv[ 1 ] = NULL;
argv = my_argv;
}
if ( execvp( argv[ 0 ], argv ) < 0 ) {
perror( "execve" );
exit( 1 );
}
Expand Down

0 comments on commit 8a91e78

Please sign in to comment.