summaryrefslogtreecommitdiffstats
path: root/zgrep.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 /zgrep.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 'zgrep.cc')
-rw-r--r--zgrep.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/zgrep.cc b/zgrep.cc
index 41317a5..d0e69e3 100644
--- a/zgrep.cc
+++ b/zgrep.cc
@@ -84,9 +84,12 @@ int zgrep_stdin( int infd, const std::vector< const char * > & grep_args )
// parent
if( grep_pid < 0 )
{ 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;
+
+ int retval = wait_for_child( grep_pid, GREP );
+ if( retval != 1 )
+ { if( pid ) kill( pid, SIGTERM ); }
+ else
+ if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( close( infd ) != 0 )
{ show_close_error( "data feeder" ); return 2; }
return retval;
@@ -146,9 +149,12 @@ int zgrep_file( int infd, const std::string & input_filename,
}
if( size < buffer_size ) break;
}
- int retval = 0;
- if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
- if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
+
+ int retval = wait_for_child( grep_pid, GREP );
+ if( retval != 1 )
+ { if( pid ) kill( pid, SIGTERM ); }
+ else
+ if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( grep_list && retval == 0 )
std::printf( "%s\n", input_filename.c_str() );
if( close( infd ) != 0 )