command-not-found: Update with new commands
[termux-packages] / packages / grep / grep.c.patch
CommitLineData
493cb560
FF
1When writing to a closed pipe, which happens with simple
2
3 seq 99999 | grep -v xxx | head -1
4
5the write() function will return an EPIPE error. The kernel also sends
6SIGPIPE to the process, which by default kills it.
7
8As the signal delivery is not immediate, grep may see EPIPE and report
9it as an error, which is annoying, especially on Android where this
10timing issue is encountered a lot more.
11
12See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23267 where it has
13been suggested to silently ignore EPIPE. That was in the context of
14SIGPIPE being ignored, but this should probably also been done to
15avoid timing issues. Feedback has been sent to the above issue and
16is awaiting mailing list approval.
17
18diff -u -r ../grep-2.25/src/grep.c ./src/grep.c
19--- ../grep-2.25/src/grep.c 2016-04-02 20:45:51.000000000 -0400
20+++ ./src/grep.c 2016-04-23 06:41:54.419351897 -0400
21@@ -1234,8 +1234,13 @@
22 if (line_buffered)
23 fflush_errno ();
24
25- if (stdout_errno)
26- error (EXIT_TROUBLE, stdout_errno, _("write error"));
27+ if (stdout_errno) {
28+ if (stdout_errno == EPIPE) {
29+ exit (EXIT_SUCCESS);
30+ } else {
31+ error (EXIT_TROUBLE, stdout_errno, _("write error"));
32+ }
33+ }
34
35 lastout = lim;
36 }