From 5959342ac76e04792920b5cccffd67a840b2193d Mon Sep 17 00:00:00 2001 From: John Hood Date: Thu, 24 Sep 2015 19:34:01 -0400 Subject: [PATCH] mosh-client: return meaningful exitstatus on network setup/teardown or other failure --- src/frontend/mosh-client.cc | 8 ++++++-- src/frontend/stmclient.cc | 5 +++-- src/frontend/stmclient.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index 3523a71..6afb6e1 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -163,12 +163,13 @@ int main( int argc, char *argv[] ) /* Adopt native locale */ set_native_locale(); + bool success = false; try { STMClient client( ip, desired_port, key, predict_mode ); client.init(); try { - client.main(); + success = client.main(); } catch ( ... ) { client.shutdown(); throw; @@ -178,16 +179,19 @@ int main( int argc, char *argv[] ) } catch ( const Network::NetworkException &e ) { fprintf( stderr, "Network exception: %s\r\n", e.what() ); + success = false; } catch ( const Crypto::CryptoException &e ) { fprintf( stderr, "Crypto exception: %s\r\n", e.what() ); + success = false; } catch ( const std::exception &e ) { fprintf( stderr, "Error: %s\r\n", e.what() ); + success = false; } printf( "\n[mosh is exiting.]\n" ); free( key ); - return 0; + return !success; } diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index 9e4d916..0c9027f 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -408,7 +408,7 @@ bool STMClient::process_resize( void ) return true; } -void STMClient::main( void ) +bool STMClient::main( void ) { /* initialize signal handling and structures */ main_init(); @@ -479,7 +479,7 @@ void STMClient::main( void ) if ( sel.signal( SIGWINCH ) ) { /* resize */ - if ( !process_resize() ) { return; } + if ( !process_resize() ) { return false; } } if ( sel.signal( SIGCONT ) ) { @@ -572,5 +572,6 @@ void STMClient::main( void ) } } } + return clean_shutdown; } diff --git a/src/frontend/stmclient.h b/src/frontend/stmclient.h index 1707f18..3ee5900 100644 --- a/src/frontend/stmclient.h +++ b/src/frontend/stmclient.h @@ -118,7 +118,7 @@ public: void init( void ); void shutdown( void ); - void main( void ); + bool main( void ); ~STMClient() {