bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep --devices=skip does not ignore FIFOs (version 2.5.1a +FIX)


From: Ken Lalonde
Subject: Re: grep --devices=skip does not ignore FIFOs (version 2.5.1a +FIX)
Date: Tue, 20 Jun 2006 16:55:36 -0400
User-agent: Mutt/1.4.2.1i

This is a third follow-up and correction to my previous bug report:

The second patch I sent has a problem: grep first opens a file,
then fstat's it to determine if it is a device.
If the file is a FIFO, the open will hang, waiting for the process
at the other end.

The patch below causes grep to stat() the file before opening it.
This produces the correct behavior, but also requires an extra
stat() call per file, which is unfortunate.


--- grep.c.orig Tue Jun 20 16:34:53 2006
+++ grep.c      Tue Jun 20 16:48:46 2006
@@ -45,6 +45,13 @@
 #undef MAX
 #define MAX(A,B) ((A) > (B) ? (A) : (B))
 
+#ifndef S_ISFIFO
+# define S_ISFIFO(m) 0
+#endif
+#ifndef S_ISSOCK
+# define S_ISSOCK(m) 0
+#endif
+
 struct stats
 {
   struct stats const *parent;
@@ -262,12 +269,7 @@
     }
   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)))
-#else
-  if (devices == SKIP_DEVICES && (S_ISCHR(stats->stat.st_mode) || 
S_ISBLK(stats->stat.st_mode)))
-#endif
-    return 0;
+  /* grepfile has already skipped devices, if requested */
   if (S_ISREG (stats->stat.st_mode))
     {
       if (file)
@@ -895,6 +897,17 @@
     }
   else
     {
+      if (devices = SKIP_DEVICES)
+        {
+          if (stat (file, &stats->stat) != 0)
+            {
+              error (0, errno, "%s", file);
+              return 1;
+            }
+          if ((S_ISCHR(stats->stat.st_mode) || S_ISBLK(stats->stat.st_mode) || 
S_ISSOCK(stats->stat.st_mode) || S_ISFIFO(stats->stat.st_mode)))
+            return 1;
+        }
+
       while ((desc = open (file, O_RDONLY)) < 0 && errno == EINTR)
        continue;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]