diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-08-14 15:50:54 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-08-14 15:50:54 +0200 |
commit | e808f69ca1d44a66566062b062efcb4c7b9bde97 (patch) | |
tree | 4d8bb97bed68bfb53b31da2515b383fee87f5f81 | |
parent | 1255c67a0af375a55ec1afb4f552541ed9a365ef (diff) | |
download | cssh-e808f69ca1d44a66566062b062efcb4c7b9bde97.tar.gz cssh-e808f69ca1d44a66566062b062efcb4c7b9bde97.tar.bz2 |
added stderr handling
-rw-r--r-- | src/cssh.c | 52 | ||||
-rw-r--r-- | src/cssh_options.ggo | 8 |
2 files changed, 56 insertions, 4 deletions
@@ -332,6 +332,7 @@ int main( int argc, char *argv[] ) while( ssh_channel_is_open( channel ) && !ssh_channel_is_eof( channel ) ) { char buffer[256]; + bool must_sleep = false; rc = ssh_channel_poll( channel, 0 ); if( rc == SSH_ERROR ) { @@ -383,6 +384,57 @@ int main( int argc, char *argv[] ) } } } + + rc = ssh_channel_poll( channel, 1 ); + if( rc == SSH_ERROR ) { + fprintf( stderr, "ERROR: ssh_channel_poll on stderr failed: %s\n", + ssh_get_error( session ) ); + ssh_channel_close( channel ); + ssh_channel_free( channel ); + ssh_disconnect( session ); + ssh_free( session ); + exit( EXIT_FAILURE ); + } + + if( rc > 0 ) { + unsigned int nread = ssh_channel_read_nonblocking( channel, buffer, sizeof( buffer ), 1 ); + if( nread == SSH_ERROR ) { + fprintf( stderr, "ERROR: ssh_channel_read_nonblocking on stderr failed: %s\n", + ssh_get_error( session ) ); + ssh_channel_close( channel ); + ssh_channel_free( channel ); + ssh_disconnect( session ); + ssh_free( session ); + exit( EXIT_FAILURE ); + } + + if( nread > 0 ) { + size_t wrc = fwrite( buffer, 1, nread, stderr ); + if( wrc < 0 ) { + fprintf( stderr, "ERROR: while writting to stderr: %s\n", + strerror( errno ) ); + ssh_channel_close( channel ); + ssh_channel_free( channel ); + ssh_disconnect( session ); + ssh_free( session ); + exit( EXIT_FAILURE ); + } + + if( wrc != nread ) { + fprintf( stderr, "ERROR: Write mismatch on stderr (%zu != %d)\n", + wrc, nread ); + ssh_channel_close( channel ); + ssh_channel_free( channel ); + ssh_disconnect( session ); + ssh_free( session ); + exit( EXIT_FAILURE ); + } + } + } + + if( must_sleep ) { + cssh_msleep( 10 ); + } } ssh_channel_send_eof( channel ); diff --git a/src/cssh_options.ggo b/src/cssh_options.ggo index 0a06621..3090e57 100644 --- a/src/cssh_options.ggo +++ b/src/cssh_options.ggo @@ -22,8 +22,8 @@ section "Main Options" int typestr="port" optional - option "hosts" H - "List of hosts to use in parallel" - string typestr="host" - multiple optional + option "hosts-file" H + "List of hosts to use in parallel (listed one per line in a file)" + string typestr="hosts-file" + optional |