bug-grep
[Top][All Lists]
Advanced

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

Re: MS-Windows build of Grep [2/4]


From: Paul Eggert
Subject: Re: MS-Windows build of Grep [2/4]
Date: Fri, 30 Dec 2011 14:47:59 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0

On 12/30/11 07:43, Jim Meyering wrote:

> Without useful stat.st_ino, there are some important tasks (e.g., dir
> traversal) that simply cannot be performed safely/reliably.

True, but a stricter approach for st_ino, while good for coreutils,
may not be as good a match for grep.  grep's philosophy in the
other place it deals with st_ino (i.e., the directory loop check)
is that when st_ino is unreliable grep disables the check; this is
"good enough" for a non-POSIXish host.

For consistency, shouldn't grep do something similar when checking
whether the input file is the same as the output file?  Not only
is this more consistent, it simplifies maintenance, and in this case
it even *increases* reliability on POSIX hosts.  Here's a proposed
patch.

=====
grep: do input==output check more like dir loop check
* src/main.c (grepfile): Just use SAME_INODE; don't bother
with SAME_REGULAR_FILE.  This works better on properly-working
POSIX hosts, since it handles the case where the file is changing
as we grep it.  It works worse on hosts that don't support st_ino
properly, but in practice this isn't that much of a problem here.
* src/system.h (same_file_attributes, SAME_REGULAR_FILE):
Remove; no longer needed.
diff --git a/src/main.c b/src/main.c
index ca6f85f..3fff5b7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1423,8 +1423,8 @@ grepfile (char const *file, struct stats *stats)
          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 == 0 && 1 < max_count
-          && S_ISREG (stats->stat.st_mode) && out_stat.st_ino
-          && SAME_REGULAR_FILE (stats->stat, out_stat))
+          && S_ISREG (out_stat.st_mode) && out_stat.st_ino
+          && SAME_INODE (stats->stat, out_stat))
         {
           error (0, 0, _("input file %s is also the output"), quote (file));
           errseen = 1;
diff --git a/src/system.h b/src/system.h
index db2fea3..f356c08 100644
--- a/src/system.h
+++ b/src/system.h
@@ -51,44 +51,5 @@ enum { EXIT_TROUBLE = 2 };
 # define initialize_main(argcp, argvp)
 #endif

-/* Do struct stat *S, *T have the same file attributes?
-
-   POSIX says that two files are identical if st_ino and st_dev are
-   the same, but many file systems incorrectly assign the same (device,
-   inode) pair to two distinct files, including:
-
-   - GNU/Linux NFS servers that export all local file systems as a
-     single NFS file system, if a local device number (st_dev) exceeds
-     255, or if a local inode number (st_ino) exceeds 16777215.
-
-   - Network Appliance NFS servers in snapshot directories; see
-     Network Appliance bug #195.
-
-   - ClearCase MVFS; see bug id ATRia04618.
-
-   Check whether two files that purport to be the same have the same
-   attributes, to work around instances of this common bug.  Do not
-   inspect all attributes, only attributes useful in checking for this
-   bug.
-
-   It's possible for two distinct files on a buggy file system to have
-   the same attributes, but it's not worth slowing down all
-   implementations (or complicating the configuration) to cater to
-   these rare cases in buggy implementations.  */
-
-#ifndef same_file_attributes
-# define same_file_attributes(s, t) \
-   ((s)->st_mode == (t)->st_mode \
-    && (s)->st_nlink == (t)->st_nlink \
-    && (s)->st_uid == (t)->st_uid \
-    && (s)->st_gid == (t)->st_gid \
-    && (s)->st_size == (t)->st_size \
-    && (s)->st_mtime == (t)->st_mtime \
-    && (s)->st_ctime == (t)->st_ctime)
-#endif
-
-#define SAME_REGULAR_FILE(s, t) \
-  (SAME_INODE (s, t) && same_file_attributes (&s, &t))
-
 #include "unlocked-io.h"
 #endif



reply via email to

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