diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-08 04:29:40 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-08 04:29:40 +0000 |
commit | 57d1e4420d7f7981a5e55ad5f66cb1534af30851 (patch) | |
tree | 7de98d0106a3940da1e3c5eb773d5a1de186a905 /ztest.cc | |
parent | Adding upstream version 1.1. (diff) | |
download | zutils-48edf68e54f97d9ec99dc505ee23126237e8be2f.tar.xz zutils-48edf68e54f97d9ec99dc505ee23126237e8be2f.zip |
Adding upstream version 1.2~pre2.upstream/1.2_pre2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'ztest.cc')
-rw-r--r-- | ztest.cc | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -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 ); } |