summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2016-09-23 20:46:19 -0700
committerJim Meyering <meyering@fb.com>2016-09-23 22:08:43 -0700
commiteaa1541d8e714621abe5a8235f4a59cbf64b2d1f (patch)
treee44044e15e141c5d58769ba2765e1a0a571d91d6
parent72aa3b232e847e8ab78093e87dc1ee6471d192ac (diff)
downloadgrep-eaa1541d8e714621abe5a8235f4a59cbf64b2d1f.tar.gz
grep: avoid unwarranted "input file 'F' is also the output" on *BSD
On *BSD systems, any command like "echo y | grep x", where grep reads from a pipe and writes to standard output, would mistakenly emit this: grep: input file '(standard input)' is also the output * src/grep.c (grepdesc): Ensure that the file descriptor we're reading is a regular one before using SAME_INODE to test whether it is the same as the descriptor open on standard output. Nelson Beebe reported privately that the foad1 tests failed on many BSD systems. Exposed by commit v2.25-2-gaf6af28. https://bugs.gnu.org/24522
-rw-r--r--src/grep.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/grep.c b/src/grep.c
index 65916ca0..3b855612 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1819,7 +1819,7 @@ grepdesc (int desc, bool command_line)
input==output, while there is no risk of infloop, there is a race
condition that could result in "alternate" output. */
if (!out_quiet && list_files == LISTFILES_NONE && 1 < max_count
- && SAME_INODE (st, out_stat))
+ && S_ISREG (st.st_mode) && SAME_INODE (st, out_stat))
{
if (! suppress_errors)
error (0, 0, _("input file %s is also the output"), quote (filename));