Description of problem:
"grep -D skip ..." should skip FIFO, BLK and CHR files, and really shouldn't
try to open them.
Note also that "grep -d skip" should skip subdirectories, but doesn't.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
0. Become root
1. mkdir /tmp/x
2. cd /tmp/x
3. mknod hdg8 b 34 8
4. mknod null c 1 3
5. mkfifo y
6. strace -eopen grep -D skip -r hello .
7. CTRL-C when it gets stuck opening the FIFO.
9. grep -D skip -r hello . & sleep 3; echo hello >y
From step 6, the strace shows:
open("./hdg8", O_RDONLY) = -1 ENXIO (No such device or address)
open("./null", O_RDONLY) = 3
open("./y", O_RDONLY <unfinished ...>
And from step 9:
grep: ./hdg8: No such device or address
+ Exit 2 grep -D skip -r hello .
Note grep actually read from the FIFO, even though it was supposed to skip it.
grep should not have attempted to open FIFO, character device or block device
files. It should also skip socket files according to the manual page and
grep's --help dump.
grep might be able to use the type information passed by the getdents() system
call under some circumstances. This is available through the libc readdir()
function. If this information is not available, it should stat the files
beforehand (fstatat() might be useful in the directory scanning case). It
could then potentially dispense with the fstat() it does after opening the
The main thing, I think, is that it shouldn't attempt to *open* one of these
special files if -D skip is given to it.
Thanks for catching it.
*** Bug 192579 has been marked as a duplicate of this bug. ***
The bug has long ago been fixed in grep CVS, but for some reason they haven't
made any new release since. The patch can be found at
Fixed in Fedora Core devel.