Only print motd for login shells, not when command is specified.

This commit is contained in:
Keith Winstein
2012-04-16 18:34:53 -04:00
parent 4326daaccc
commit 3ed9c0fb77
+11 -3
View File
@@ -74,7 +74,8 @@ void serve( int host_fd,
ServerConnection &network ); ServerConnection &network );
int run_server( const char *desired_ip, const char *desired_port, int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[], const int colors, bool verbose ); const string &command_path, char *command_argv[],
const int colors, bool verbose, bool with_motd );
using namespace std; using namespace std;
@@ -196,6 +197,8 @@ int main( int argc, char *argv[] )
exit( 1 ); exit( 1 );
} }
bool with_motd = false;
/* Get shell */ /* Get shell */
char *my_argv[ 2 ]; char *my_argv[ 2 ];
if ( !command_argv ) { if ( !command_argv ) {
@@ -228,6 +231,8 @@ int main( int argc, char *argv[] )
my_argv[ 0 ] = strdup( shell_name.c_str() ); my_argv[ 0 ] = strdup( shell_name.c_str() );
my_argv[ 1 ] = NULL; my_argv[ 1 ] = NULL;
command_argv = my_argv; command_argv = my_argv;
with_motd = true;
} }
if ( command_path.empty() ) { if ( command_path.empty() ) {
@@ -260,7 +265,7 @@ int main( int argc, char *argv[] )
} }
try { try {
return run_server( desired_ip, desired_port, command_path, command_argv, colors, verbose ); return run_server( desired_ip, desired_port, command_path, command_argv, colors, verbose, with_motd );
} catch ( Network::NetworkException e ) { } catch ( Network::NetworkException e ) {
fprintf( stderr, "Network exception: %s: %s\n", fprintf( stderr, "Network exception: %s: %s\n",
e.function.c_str(), strerror( e.the_errno ) ); e.function.c_str(), strerror( e.the_errno ) );
@@ -273,7 +278,8 @@ int main( int argc, char *argv[] )
} }
int run_server( const char *desired_ip, const char *desired_port, int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[], const int colors, bool verbose ) { const string &command_path, char *command_argv[],
const int colors, bool verbose, bool with_motd ) {
/* get initial window size */ /* get initial window size */
struct winsize window_size; struct winsize window_size;
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) { if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
@@ -391,7 +397,9 @@ int run_server( const char *desired_ip, const char *desired_port,
exit( 1 ); exit( 1 );
} }
if ( with_motd ) {
print_motd(); print_motd();
}
if ( execvp( command_path.c_str(), command_argv ) < 0 ) { if ( execvp( command_path.c_str(), command_argv ) < 0 ) {
perror( "execvp" ); perror( "execvp" );