summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-12-12 16:31:32 (GMT)
committerPaul Eggert <eggert@cs.ucla.edu>2016-12-12 16:34:00 (GMT)
commitca66d6f9cc769c3cb6ff3293725b8742840b98fa (patch)
tree0d070ef3109c552a8e866ed8ac2b748d4fd4fc3f
parenta3721c43f96beb255c533118bfaba1ddf8d9a6be (diff)
downloadgrep-ca66d6f9cc769c3cb6ff3293725b8742840b98fa.zip
grep-ca66d6f9cc769c3cb6ff3293725b8742840b98fa.tar.gz
grep-ca66d6f9cc769c3cb6ff3293725b8742840b98fa.tar.bz2
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.
-rw-r--r--NEWS6
-rw-r--r--src/grep.c9
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/proc18
4 files changed, 31 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index f33001d..aa0483b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU grep NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ grep no longer fails when standard input is a file in the Linux
+ /proc file system and standard output is /dev/null.
+ [bug introduced in grep-2.27]
+
* Noteworthy changes in release 2.27 (2016-12-06) [stable]
diff --git a/src/grep.c b/src/grep.c
index 1e910cb..30e0f54 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);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3ded7a7..52e2b9e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -141,6 +141,7 @@ TESTS = \
pcre-z \
posix-bracket \
prefix-of-multibyte \
+ proc \
r-dot \
repetition-overflow \
reversed-range-endpoints \
diff --git a/tests/proc b/tests/proc
new file mode 100755
index 0000000..aeb4a50
--- /dev/null
+++ b/tests/proc
@@ -0,0 +1,18 @@
+#! /bin/sh
+# Test the /proc file system if available.
+
+# Copyright 2016 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+test -r /proc/self/status || skip_ 'No /proc/self/status on this platform.'
+
+grep '^' </proc/self/status >/dev/null || fail=1
+
+Exit $fail