Allow stm-server to start named processes instead of just the shell

This commit is contained in:
Keith Winstein
2012-01-15 18:25:27 -05:00
parent 8ce54faca9
commit e4a128e677
+30 -14
View File
@@ -24,7 +24,7 @@ void serve( int host_fd );
using namespace std; using namespace std;
int main( void ) int main( int argc, char *argv[] )
{ {
int master; int master;
struct termios child_termios; struct termios child_termios;
@@ -80,20 +80,36 @@ int main( void )
} }
/* get shell name */ /* get shell name */
struct passwd *pw = getpwuid( geteuid() ); if ( argc <= 1 ) {
if ( pw == NULL ) { struct passwd *pw = getpwuid( geteuid() );
perror( "getpwuid" ); if ( pw == NULL ) {
exit( 1 ); perror( "getpwuid" );
} exit( 1 );
}
char *my_argv[ 2 ]; 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;
if ( execve( pw->pw_shell, my_argv, environ ) < 0 ) { if ( execve( pw->pw_shell, my_argv, environ ) < 0 ) {
perror( "execve" ); perror( "execve" );
exit( 1 ); exit( 1 );
}
} else {
char **my_argv = (char **)malloc( (argc - 1) * sizeof( char * ) );
assert( my_argv );
for ( int i = 0; i < argc - 1; i++ ) {
my_argv[ i ] = strdup( argv[ i + 1 ] );
assert( my_argv[ i ] );
my_argv[ argc - 1 ] = NULL;
}
if ( execve( my_argv[ 0 ], my_argv, environ ) < 0 ) {
perror( "execve" );
exit( 1 );
}
} }
exit( 0 ); exit( 0 );
} else { } else {