summaryrefslogtreecommitdiff
path: root/src/grep.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-12-12 08:31:32 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-12-12 08:34:00 -0800
commitca66d6f9cc769c3cb6ff3293725b8742840b98fa (patch)
tree0d070ef3109c552a8e866ed8ac2b748d4fd4fc3f /src/grep.c
parenta3721c43f96beb255c533118bfaba1ddf8d9a6be (diff)
downloadgrep-ca66d6f9cc769c3cb6ff3293725b8742840b98fa.tar.gz
grep: work around proc lseek glitch
Problem reported by Andreas Schwab (Bug#25180). * NEWS: Document this. * src/grep.c (finalize_input): Ignore EINVAL lseek failures. * tests/Makefile.am (TESTS): Add proc. * tests/proc: New file.
Diffstat (limited to 'src/grep.c')
-rw-r--r--src/grep.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/grep.c b/src/grep.c
index 1e910cb7..30e0f54a 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1760,9 +1760,12 @@ finalize_input (int fd, struct stat const *st, bool ineof)
{
if (fd == STDIN_FILENO
&& (outleft
- ? (!ineof && (seek_failed
- ? ! drain_input (fd, st)
- : lseek (fd, 0, SEEK_END) < 0))
+ ? (!ineof
+ && (seek_failed
+ || (lseek (fd, 0, SEEK_END) < 0
+ /* Linux proc file system has EINVAL (Bug#25180). */
+ && errno != EINVAL))
+ && ! drain_input (fd, st))
: (bufoffset != after_last_match && !seek_failed
&& lseek (fd, after_last_match, SEEK_SET) < 0)))
suppressible_error (errno);