summaryrefslogtreecommitdiffstats
path: root/ztest.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:29:58 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:29:58 +0000
commit4646c2987eba0ba70050daf3c9fb450510a30237 (patch)
treeb1312f8c64fd61a3097b553507d00cac44b3c4bd /ztest.cc
parentAdding debian version 1.1-1. (diff)
downloadzutils-4646c2987eba0ba70050daf3c9fb450510a30237.tar.xz
zutils-4646c2987eba0ba70050daf3c9fb450510a30237.zip
Merging upstream version 1.2~pre2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'ztest.cc')
-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 );
}