From 4646c2987eba0ba70050daf3c9fb450510a30237 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 8 Nov 2015 05:29:58 +0100 Subject: Merging upstream version 1.2~pre2. Signed-off-by: Daniel Baumann --- ztest.cc | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'ztest.cc') diff --git a/ztest.cc b/ztest.cc index 20296b9..79f32dd 100644 --- a/ztest.cc +++ b/ztest.cc @@ -59,7 +59,20 @@ int ztest_stdin( const int infd, int format_index, { show_error( "Can't create pipe", errno ); return 1; } const pid_t pid = fork(); - if( pid == 0 ) // child1 (compressor) + if( pid == 0 ) // child1 (compressor 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( "data feeder" ); _exit( 1 ); } + _exit( 0 ); + } + if( pid < 0 ) // parent + { show_fork_error( "data feeder" ); return 1; } + + const pid_t pid2 = fork(); + if( pid2 == 0 ) // child2 (compressor) { if( dup2( fda[0], STDIN_FILENO ) >= 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 ) @@ -81,25 +94,13 @@ int ztest_stdin( const int infd, int format_index, show_exec_error( compressor_name ); _exit( 1 ); } - if( pid < 0 ) // parent - { show_fork_error( compressor_name ); return 1; } - - const pid_t pid2 = fork(); - if( pid2 == 0 ) // child2 (compressor 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( "data feeder" ); _exit( 1 ); } - _exit( 0 ); - } if( pid2 < 0 ) // parent - { show_fork_error( "data feeder" ); return 1; } + { show_fork_error( compressor_name ); return 1; } close( fda[0] ); close( fda[1] ); - int retval = wait_for_child( pid, compressor_name, 1 ); - if( retval == 0 && wait_for_child( pid2, "data feeder" ) != 0 ) + const bool isgzxz = ( format_index == fmt_gz || format_index == fmt_xz ); + int retval = wait_for_child( pid2, compressor_name, 1, isgzxz ); + if( retval == 0 && wait_for_child( pid, "data feeder" ) != 0 ) retval = 1; return retval; } @@ -141,5 +142,6 @@ int ztest_file( const int infd, int format_index, if( pid < 0 ) // parent { show_fork_error( compressor_name ); return 1; } - return wait_for_child( pid, compressor_name, 1 ); + const bool isgzxz = ( format_index == fmt_gz || format_index == fmt_xz ); + return wait_for_child( pid, compressor_name, 1, isgzxz ); } -- cgit v1.2.3