From: girst Date: Fri, 28 Jul 2017 22:20:39 +0000 (+0200) Subject: fixed sigpipe X-Git-Url: https://git.gir.st/forkaftergrep.git/commitdiff_plain/cebe28dd8176a26f2797c9a50e9f9a8796fd958c?ds=sidebyside fixed sigpipe --- 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 !