diff options
Diffstat (limited to '')
-rw-r--r-- | ztest.cc | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -42,12 +42,12 @@ int ztest_stdin( const int infd, int magic_size = 0; if( !test_format( infd, file_type, &magic_data, &magic_size ) ) { show_error( "Unknown data format read from stdin." ); return 2; } - int fda[2]; + int fda[2]; // pipe from feeder if( pipe( fda ) < 0 ) { show_error( "Can't create pipe", errno ); return 1; } - const pid_t pid = fork(); - if( pid == 0 ) // child (decompressor) + const pid_t pid = fork(); + if( pid == 0 ) // child1 (decompressor) { if( dup2( fda[0], STDIN_FILENO ) >= 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 ) @@ -66,11 +66,26 @@ int ztest_stdin( const int infd, // parent if( pid < 0 ) { show_fork_error( file_type.c_str() ); return 1; } - close( fda[0] ); - if( !feed_data( infd, fda[1], magic_data, magic_size ) ) return 1; - if( close( fda[1] ) != 0 ) - { show_close_error( "data feeder" ); return 1; } - return wait_for_child( pid, file_type.c_str() ); + + const pid_t pid2 = fork(); + if( pid2 == 0 ) // child2 (decompressor feeder) + { + if( close( fda[0] ) != 0 || + !feed_data( infd, fda[1], magic_data, magic_size ) ) + _exit( 1 ); + if( close( fda[1] ) != 0 ) + { show_close_error( "decompressor feeder" ); _exit( 1 ); } + _exit( 0 ); + } + // parent + if( pid2 < 0 ) + { show_fork_error( "decompressor feeder" ); return 1; } + + close( fda[0] ); close( fda[1] ); + int retval = wait_for_child( pid, file_type.c_str(), 1 ); + if( retval == 0 && wait_for_child( pid2, "decompressor feeder" ) != 0 ) + retval = 1; + return retval; } @@ -101,5 +116,6 @@ int ztest_file( const int infd, const std::string & input_filename, // parent if( pid < 0 ) { show_fork_error( file_type.c_str() ); return 1; } - return wait_for_child( pid, file_type.c_str() ); + + return wait_for_child( pid, file_type.c_str(), 1 ); } |