summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2021-12-28 19:22:58 +0000
committerchristos <christos@NetBSD.org>2021-12-28 19:22:58 +0000
commitda44da660c17417f5467a4843b72620437bbfc81 (patch)
tree3b4f73413bc487f55b5495a394d3cfba30d70e98
parent5f723f6628090a40b620528089940999bf090113 (diff)
Open with non-blocking I/O and then reset the flags to avoid blocking for
FIFOs. This is a lot easier to do than adding another stat(2) to avoid open(2).
-rw-r--r--external/gpl2/grep/dist/src/grep.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/external/gpl2/grep/dist/src/grep.c b/external/gpl2/grep/dist/src/grep.c
index 13c17ff85ab..762c401c413 100644
--- a/external/gpl2/grep/dist/src/grep.c
+++ b/external/gpl2/grep/dist/src/grep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: grep.c,v 1.3 2021/12/28 14:59:02 christos Exp $ */
+/* $NetBSD: grep.c,v 1.4 2021/12/28 19:22:58 christos Exp $ */
/* grep.c - main driver file for grep.
Copyright 1992, 1997-1999, 2000 Free Software Foundation, Inc.
@@ -911,9 +911,12 @@ grepfile (char const *file, struct stats *stats)
}
else
{
- while ((desc = open (file, O_RDONLY)) < 0 && errno == EINTR)
+ while ((desc = open (file, O_RDONLY | O_NONBLOCK)) < 0 && errno == EINTR)
continue;
+ if (desc >= 0 && (status = fcntl (desc, F_GETFL, 0)) != -1)
+ fcntl (desc, F_SETFL, status & ~O_NONBLOCK);
+
if (desc < 0)
{
int e = errno;