summaryrefslogtreecommitdiffstats
path: root/ztest.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:29:40 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:29:40 +0000
commit57d1e4420d7f7981a5e55ad5f66cb1534af30851 (patch)
tree7de98d0106a3940da1e3c5eb773d5a1de186a905 /ztest.cc
parentAdding upstream version 1.1. (diff)
downloadzutils-57d1e4420d7f7981a5e55ad5f66cb1534af30851.tar.xz
zutils-57d1e4420d7f7981a5e55ad5f66cb1534af30851.zip
Adding upstream version 1.2~pre2.upstream/1.2_pre2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r--ztest.cc38
1 files changed, 20 insertions, 18 deletions
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 );
}