termemu: respect $SHELL and exec argv if given

Signed-off-by: John Hood <cgull@glup.org>
This commit is contained in:
John Hood
2014-02-12 00:18:43 -05:00
parent 73fd6442c5
commit 8a91e78349
+12 -5
View File
@@ -72,7 +72,7 @@ const size_t buf_size = 16384;
static void emulate_terminal( int fd ); static void emulate_terminal( int fd );
int main( void ) int main( int argc, char *argv[] )
{ {
int master; int master;
struct termios saved_termios, raw_termios, child_termios; struct termios saved_termios, raw_termios, child_termios;
@@ -116,19 +116,26 @@ int main( void )
exit( 1 ); exit( 1 );
} }
char *my_argv[ 2 ];
if ( argc > 1 ) {
argv++;
} else {
/* get shell name */ /* get shell name */
my_argv[ 0 ] = getenv( "SHELL" );
if ( my_argv[ 0 ] == NULL ) {
struct passwd *pw = getpwuid( geteuid() ); struct passwd *pw = getpwuid( geteuid() );
if ( pw == NULL ) { if ( pw == NULL ) {
perror( "getpwuid" ); perror( "getpwuid" );
exit( 1 ); exit( 1 );
} }
char *my_argv[ 2 ];
my_argv[ 0 ] = strdup( pw->pw_shell ); my_argv[ 0 ] = strdup( pw->pw_shell );
}
assert( my_argv[ 0 ] ); assert( my_argv[ 0 ] );
my_argv[ 1 ] = NULL; my_argv[ 1 ] = NULL;
argv = my_argv;
if ( execv( pw->pw_shell, my_argv ) < 0 ) { }
if ( execvp( argv[ 0 ], argv ) < 0 ) {
perror( "execve" ); perror( "execve" );
exit( 1 ); exit( 1 );
} }