Package: grep / 2.27-2

upstream-grep-work-around-proc-lseek-glitch.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From ca66d6f9cc769c3cb6ff3293725b8742840b98fa Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 12 Dec 2016 08:31:32 -0800
Subject: [PATCH] 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.
---

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);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3ded7a78..52e2b9e3 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 00000000..aeb4a50f
--- /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
-- 
2.11.0