1
0
Fork 0

Merging upstream version 0.9~rc1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-24 05:04:40 +01:00
parent 4f4c7c8781
commit 6503461316
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
19 changed files with 126 additions and 131 deletions

View file

@ -72,23 +72,23 @@ int zgrep_stdin( int infd, const std::vector< const char * > & grep_args )
if( dup2( infd, STDIN_FILENO ) >= 0 && close( infd ) == 0 )
{
const char ** const argv = new const char *[grep_args.size()+2];
argv[0] = "grep";
argv[0] = GREP;
for( unsigned int i = 0; i < grep_args.size(); ++i )
argv[i+1] = grep_args[i];
argv[grep_args.size()+1] = 0;
execvp( argv[0], (char **)argv );
}
show_error( "Can't exec `grep'." );
show_exec_error( GREP );
_exit( 2 );
}
// parent
if( grep_pid < 0 )
{ show_error( "Can't fork `grep'", errno ); return 2; }
{ show_fork_error( GREP ); return 2; }
int retval = 0;
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( wait_for_child( grep_pid, "grep" ) != 0 ) retval = 2;
if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
if( close( infd ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); return 2; }
{ show_close_error( "data feeder" ); return 2; }
return retval;
}
@ -110,19 +110,19 @@ int zgrep_file( int infd, const std::string & input_filename,
close( infd ) == 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 )
{
const char ** const argv = new const char *[grep_args.size()+2];
argv[0] = "grep";
argv[0] = GREP;
for( unsigned int i = 0; i < grep_args.size(); ++i )
argv[i+1] = grep_args[i];
argv[grep_args.size()+1] = 0;
execvp( argv[0], (char **)argv );
}
show_error( "Can't exec `grep'." );
show_exec_error( GREP );
_exit( 2 );
}
// parent
close( fda[1] );
if( grep_pid < 0 )
{ show_error( "Can't fork `grep'", errno ); return 2; }
{ show_fork_error( GREP ); return 2; }
enum { buffer_size = 256 };
uint8_t buffer[buffer_size];
bool line_begin = true;
@ -148,12 +148,12 @@ int zgrep_file( int infd, const std::string & input_filename,
}
int retval = 0;
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( wait_for_child( grep_pid, "grep" ) != 0 ) retval = 2;
if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
if( grep_list && retval == 0 )
std::printf( "%s\n", input_filename.c_str() );
if( close( infd ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); return 2; }
{ show_close_error( "data feeder" ); return 2; }
if( close( fda[0] ) != 0 )
{ show_error( "Can't close output of grep", errno ); return 2; }
{ show_close_error( GREP ); return 2; }
return retval;
}