|
From: | Paolo Bonzini |
Subject: | Re: [bug #17457] "grep -r foo . > somefile" goes into an infinite loop |
Date: | Sat, 06 Feb 2010 16:53:54 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.7) Gecko/20100120 Fedora/3.0.1-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.1 |
Actually, how about detecting this and diagnosing the problem rather than falling into the infloop? This currently evokes an infloop for me: $ seq 1000000> k $ grep 111 k>> k However, simply detecting when the output FD is also an input FD is not enough, since this variant does not get stuck: $ seq 1000> k $ grep 111 k>> k
Whether it gets stuck is mainly a function of the buffer size for the file. Certainly whatever is added at the end of "k" matches, so it will be added over and over.
This is a problem for every Unix utility that reads files sequentially (e.g. sed or, from coreutils, cut, cat, fmt, tail, comm).
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |