From cbeda2d2fe1608837cd11b92e697ac0192d0c86f Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sun, 18 Mar 2012 03:53:01 -0400 Subject: [PATCH] Don't die immediately on broken command --- src/frontend/mosh-server.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index 0320c4d..23c629c 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -39,6 +39,7 @@ #include #include #include +#include extern "C" { #include "selfpipe.h" @@ -73,6 +74,14 @@ void print_usage( const char *argv0 ) fprintf( stderr, "Usage: %s new [-s] [-i LOCALADDR] [-p PORT] [-- COMMAND...]\n", argv0 ); } +void spin( void ) +{ + struct timespec req; + req.tv_sec = 0; + req.tv_nsec = 100000000; /* 0.1 sec */ + nanosleep( &req, NULL ); +} + string get_SSH_IP( void ) { const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" ); @@ -94,7 +103,7 @@ int main( int argc, char *argv[] ) /* strip off command */ for ( int i = 0; i < argc; i++ ) { - if ( 0 == strcmp( argv[ i ], "--" ) ) { /* start of command */ + if ( 0 == strcmp( argv[ i ], "--" ) ) { /* -- is mandatory */ if ( i != argc - 1 ) { command = argv + i + 1; } @@ -126,6 +135,7 @@ int main( int argc, char *argv[] ) } } } else if ( argc == 1 ) { + /* legacy argument parsing for older client wrapper script */ /* do nothing */ } else if ( argc == 2 ) { desired_ip = argv[ 1 ]; @@ -463,7 +473,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network ssize_t bytes_read = read( pollfds[ 1 ].fd, buf, buf_size ); if ( bytes_read == 0 ) { /* EOF */ if ( !network.has_remote_addr() ) { - return; + spin(); /* let 60-second timer take care of this */ } else if ( !network.shutdown_in_progress() ) { network.start_shutdown(); } @@ -514,7 +524,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network if ( network.has_remote_addr() ) { network.start_shutdown(); } else { - break; + spin(); /* let 60-second timer take care of this */ } } @@ -565,7 +575,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network network.tick(); } catch ( Network::NetworkException e ) { fprintf( stderr, "%s: %s\n", e.function.c_str(), strerror( e.the_errno ) ); - sleep( 1 ); + spin(); } catch ( Crypto::CryptoException e ) { fprintf( stderr, "Crypto exception: %s\n", e.text.c_str() ); }