From 5279da03ae7a21a314eed01383d87f4252d0897b Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Fri, 23 Sep 2016 20:46:19 -0700
Subject: [PATCH] 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.
---
 src/grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/grep.c b/src/grep.c
index 65916ca..3b85561 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));
-- 
2.8.0-rc2

