diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-12-31 17:54:59 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-12-31 17:58:24 -0800 |
commit | ca0d4f3bae56c486ec1d49d72c9ed6924236babc (patch) | |
tree | 621ea748502843188234bb3f261dda5c4263c810 | |
parent | 71e02fa1fde638f8ae6d4bd5f985e6d3c2bd65e8 (diff) | |
download | grep-ca0d4f3bae56c486ec1d49d72c9ed6924236babc.tar.gz |
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.
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/system.h | 39 |
2 files changed, 2 insertions, 41 deletions
@@ -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 db2fea3f..f356c086 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 |