Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jan 2013 03:23:14 +0000 (UTC)
From:      David Xu <davidxu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r245761 - head/gnu/usr.bin/grep
Message-ID:  <201301220323.r0M3NEVE075690@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: davidxu
Date: Tue Jan 22 03:23:14 2013
New Revision: 245761
URL: http://svnweb.freebsd.org/changeset/base/245761

Log:
  Make "-D skip" option work with FIFO by opening file in non-blocking mode.
  
  Reviewed by:	jhb
  Tested by:	delphij

Modified:
  head/gnu/usr.bin/grep/grep.c

Modified: head/gnu/usr.bin/grep/grep.c
==============================================================================
--- head/gnu/usr.bin/grep/grep.c	Tue Jan 22 02:57:53 2013	(r245760)
+++ head/gnu/usr.bin/grep/grep.c	Tue Jan 22 03:23:14 2013	(r245761)
@@ -304,7 +304,7 @@ reset (int fd, char const *file, struct 
   if (directories == SKIP_DIRECTORIES && S_ISDIR (stats->stat.st_mode))
     return 0;
 #ifndef DJGPP
-  if (devices == SKIP_DEVICES && (S_ISCHR(stats->stat.st_mode) || S_ISBLK(stats->stat.st_mode) || S_ISSOCK(stats->stat.st_mode)))
+  if (devices == SKIP_DEVICES && (S_ISCHR(stats->stat.st_mode) || S_ISBLK(stats->stat.st_mode) || S_ISSOCK(stats->stat.st_mode) || S_ISFIFO(stats->stat.st_mode)))
 #else
   if (devices == SKIP_DEVICES && (S_ISCHR(stats->stat.st_mode) || S_ISBLK(stats->stat.st_mode)))
 #endif
@@ -942,6 +942,7 @@ grepfile (char const *file, struct stats
   int desc;
   int count;
   int status;
+  int flags;
 
   if (! file)
     {
@@ -950,7 +951,7 @@ grepfile (char const *file, struct 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)
@@ -990,6 +991,9 @@ grepfile (char const *file, struct stats
 	  return 1;
 	}
 
+      flags = fcntl(desc, F_GETFL);
+      flags &= ~O_NONBLOCK;
+      fcntl(desc, F_SETFL, flags);
       filename = file;
     }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301220323.r0M3NEVE075690>