summaryrefslogtreecommitdiffstats
path: root/ztest.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:19:42 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:19:42 +0000
commit511feb57cfea29b1f6ba303cedd1456f5cecd69e (patch)
treed2aaf1e03feec10c28a6e5d156213b3eb76613ea /ztest.cc
parentAdding debian version 0.9~rc1-1. (diff)
downloadzutils-511feb57cfea29b1f6ba303cedd1456f5cecd69e.tar.xz
zutils-511feb57cfea29b1f6ba303cedd1456f5cecd69e.zip
Merging upstream version 0.9~rc2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'ztest.cc')
-rw-r--r--ztest.cc34
1 files changed, 25 insertions, 9 deletions
diff --git a/ztest.cc b/ztest.cc
index 3672aa8..0193bfa 100644
--- a/ztest.cc
+++ b/ztest.cc
@@ -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 );
}