summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mars-attacks.org>2011-11-28 15:45:19 +0100
committerJim Meyering <meyering@redhat.com>2011-12-11 20:44:07 +0100
commit979592944f06bddb108458073239d2ff52d2c475 (patch)
treeceab5d62246471cf95246ca2dceae04f72732848
parent9d68b23adfe963387525a5a3e8eb84957ee17212 (diff)
downloadgrep-979592944f06bddb108458073239d2ff52d2c475.tar.gz
do not reject "grep -qr . > out"
The recent fix to avoid an infinite disk-filling loop, commit 5e20a38a, introduced a minor regression. If you use grep with -q and -r, and redirect output to a file that will be traversed, then grep would reject the command, even though it will generate no output. In that case, there is no risk of an infinite loop. * src/main.c (grepfile): Do not reject input == output when using --quiet/--silent (-q). Reported by J H Wilson in http://bugs.mageia.org/show_bug.cgi?id=3501 forwarded by Nicolas Vigier to https://savannah.gnu.org/bugs/?34917
-rw-r--r--src/main.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index c70156f6..c81342fe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1225,8 +1225,10 @@ grepfile (char const *file, struct stats *stats)
disk before we open this file, we can end up reading and matching
those lines and appending them to the file from which we're reading.
Then we'd have what appears to be an infinite loop that'd terminate
- only upon filling the output file system or reaching a quota. */
- if (S_ISREG (stats->stat.st_mode) && out_stat.st_ino
+ only upon filling the output file system or reaching a quota.
+ However, there is no risk of an infinite loop when we know that
+ grep will generate no output (-q). */
+ if (!out_quiet && S_ISREG (stats->stat.st_mode) && out_stat.st_ino
&& SAME_REGULAR_FILE (stats->stat, out_stat))
{
error (0, 0, _("input file %s is also the output"), quote (file));