Bug 189580 - grep -D skip is not honoured
grep -D skip is not honoured
Product: Fedora
Classification: Fedora
Component: grep (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
Mike McLean
: 192579 (view as bug list)
Depends On:
Blocks: FC6Target
  Show dependency treegraph
Reported: 2006-04-21 07:52 EDT by David Howells
Modified: 2007-11-30 17:11 EST (History)
2 users (show)

See Also:
Fixed In Version: 2.5.1-54
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-05-31 05:45:41 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description David Howells 2006-04-21 07:52:13 EDT
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): 
How reproducible: 
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. 
And then: 
9. grep -D skip -r hello . & sleep 3; echo hello >y 
Actual results: 
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: 
[1] 32746 
grep: ./hdg8: No such device or address 
[1]+  Exit 2                  grep -D skip -r hello . 
Note grep actually read from the FIFO, even though it was supposed to skip it. 
Expected results: 
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. 
Additional info: 
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.
Comment 1 Tim Waugh 2006-04-21 08:02:17 EDT
Thanks for catching it.
Comment 2 Tim Waugh 2006-05-21 05:44:52 EDT
*** Bug 192579 has been marked as a duplicate of this bug. ***
Comment 3 Ingo van Lil 2006-05-31 03:40:08 EDT
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
Comment 4 Tim Waugh 2006-05-31 05:45:41 EDT
Fixed in Fedora Core devel.

Note You need to log in before you can comment on or make changes to this bug.