From cebe28dd8176a26f2797c9a50e9f9a8796fd958c Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 29 Jul 2017 00:20:39 +0200 Subject: [PATCH] fixed sigpipe --- fag.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fag.c b/fag.c index 32fde76..6479978 100644 --- a/fag.c +++ b/fag.c @@ -1,11 +1,11 @@ /* forkaftergrep (C) 2017 Tobias Girstmair, GPLv3 */ //TODO: if grep exits with an error, fag thinks a match was found -//TODO: sometimes fag exits with code 141 (128+SIGPIPE) (line 190) #define _XOPEN_SOURCE 500 #define _DEFAULT_SOURCE #include #include +#include #include #include #include @@ -80,6 +80,8 @@ int main (int argc, char** argv) { return EX_USAGE; } + signal (SIGPIPE, SIG_IGN); /* ignore broken pipe between fag and grep */ + int retval = fork_after_grep (opts); return retval; @@ -187,7 +189,7 @@ int fork_after_grep (struct opt opts) { write(STDERR_FILENO, buf, nbytes); } - write(grep_pipefd[1], buf, nbytes); //TODO: sometimes gets SIGPIPE here + write(grep_pipefd[1], buf, nbytes); /* can cause SIGPIPE if grep exited, therefore signal will be ignored */ } // TODO: exits with `0' even if `grep' exits with code > 0 ! -- 2.39.3