From 354dff39c8d7708d91b42bf6af4e1e2cc09f82c3 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Thu, 9 Feb 2012 01:45:03 -0500 Subject: [PATCH] Catch and prettyprint exceptions even in setup phase --- src/frontend/mosh-client.cc | 25 ++++++++++++++++++++----- src/frontend/mosh-server.cc | 11 ++++++++++- src/frontend/stmclient.cc | 4 ++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index 724a2f2..c112056 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -60,13 +60,28 @@ int main( int argc, char *argv[] ) exit( 1 ); } - STMClient client( ip, port, key ); + try { + STMClient client( ip, port, key ); + client.init(); - client.init(); + try { + client.main(); + } catch ( Network::NetworkException e ) { + fprintf( stderr, "Network exception: %s: %s\r\n", + e.function.c_str(), strerror( e.the_errno ) ); + } catch ( Crypto::CryptoException e ) { + fprintf( stderr, "Crypto exception: %s\r\n", + e.text.c_str() ); + } - client.main(); - - client.shutdown(); + client.shutdown(); + } catch ( Network::NetworkException e ) { + fprintf( stderr, "Network exception: %s: %s\r\n", + e.function.c_str(), strerror( e.the_errno ) ); + } catch ( Crypto::CryptoException e ) { + fprintf( stderr, "Crypto exception: %s\r\n", + e.text.c_str() ); + } printf( "\n[mosh is exiting.]\n" ); diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index 1d3deae..bff7dca 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -127,7 +127,16 @@ int main( int argc, char *argv[] ) exit( 0 ); } else { /* parent */ - serve( master, desired_ip ); + try { + serve( master, desired_ip ); + } catch ( Network::NetworkException e ) { + fprintf( stderr, "Network exception: %s: %s\n", + e.function.c_str(), strerror( e.the_errno ) ); + } catch ( Crypto::CryptoException e ) { + fprintf( stderr, "Crypto exception: %s\n", + e.text.c_str() ); + } + if ( close( master ) < 0 ) { perror( "close" ); exit( 1 ); diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index c301fc7..81a81d8 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -153,6 +153,10 @@ void STMClient::main_init( void ) void STMClient::output_new_frame( void ) { + if ( !network ) { /* clean shutdown even when not initialized */ + return; + } + /* fetch target state */ Terminal::Framebuffer new_state( network->get_latest_remote_state().state.get_fb() );