Merging upstream version 0.9~rc2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5a7d30d9fd
commit
634a6bfc0f
21 changed files with 133 additions and 71 deletions
34
ztest.cc
34
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 );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue