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: Jim Meyering
Subject: Re: MS-Windows build of Grep [2/4]
Date: Sat, 31 Dec 2011 09:40:06 +0100

Paul Eggert wrote:
> 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))

Thanks.  That simplification is a good change, since even with
non-POSIX file systems like those mentioned in the comment,
the cases in which SAME_INODE and SAME_REGULAR_FILE differ
are not likely to arise in grep usage where input==output.



reply via email to

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