diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-09-06 10:08:46 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-09-06 10:08:46 +0200 |
commit | b2ca2930a80d738c1aa455569850ed98cd722000 (patch) | |
tree | 7641e40eab533589be35431db203f2519c8f22a3 | |
parent | 45e154f4e289f898ef4a49212239770c4ec20f04 (diff) | |
download | cssh-b2ca2930a80d738c1aa455569850ed98cd722000.tar.gz cssh-b2ca2930a80d738c1aa455569850ed98cd722000.tar.bz2 |
single host copies should not create a host directory structure
-rw-r--r-- | src/cssh.c | 51 |
1 files changed, 30 insertions, 21 deletions
@@ -1100,34 +1100,43 @@ int main( int argc, char *argv[] ) } rc = push_dir_stack( &dir_stack[i], pwd ); - - size_t len = strlen( pwd ) + 2 + strlen( host[i] ); - char *full_path = (char *)malloc( len ); - if( full_path == NULL ) { - fprintf( stderr, "ERROR: Memory allocation failed for full path of basse directory for host '%s'\n", + if( rc < 0 ) { + fprintf( stderr, "ERROR: failed to push current directory to stack for host '%s'\n", host[i] ); free( pwd ); cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } - snprintf( full_path, len, "%s/%s", pwd, host[i] ); - rc = push_dir_stack( &dir_stack[i], full_path ); - if( rc < 0 ) { - fprintf( stderr, "ERROR: failed remember initial base directory '%s' in directory stack\n", - pwd ); + if( nof_sessions > 1 ) { + size_t len = strlen( pwd ) + 2 + strlen( host[i] ); + char *full_path = (char *)malloc( len ); + if( full_path == NULL ) { + fprintf( stderr, "ERROR: Memory allocation failed for full path of base directory for host '%s'\n", + host[i] ); + free( pwd ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); + } + snprintf( full_path, len, "%s/%s", pwd, host[i] ); + rc = push_dir_stack( &dir_stack[i], full_path ); + + if( rc < 0 ) { + fprintf( stderr, "ERROR: failed remember initial base directory '%s' in directory stack\n", + pwd ); + free( pwd ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); + } free( pwd ); - cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 ); - exit( EXIT_FAILURE ); - } - free( pwd ); - - rc = mkdir( full_path, 0750 ); - if( rc < 0 ) { - fprintf( stderr, "ERROR: failed to create base directory '%s' for host '%s': %s\n", - full_path, host[i], strerror( errno ) ); - cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 ); - exit( EXIT_FAILURE ); + + rc = mkdir( full_path, 0750 ); + if( rc < 0 ) { + fprintf( stderr, "ERROR: failed to create base directory '%s' for host '%s': %s\n", + full_path, host[i], strerror( errno ) ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); + } } } |