Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 189580 - grep -D skip is not honoured
Summary: grep -D skip is not honoured
Alias: None
Product: Fedora
Classification: Fedora
Component: grep
Version: 5
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Tim Waugh
QA Contact: Mike McLean
: 192579 (view as bug list)
Depends On:
Blocks: FC6Target
TreeView+ depends on / blocked
Reported: 2006-04-21 11:52 UTC by David Howells
Modified: 2007-11-30 22:11 UTC (History)
2 users (show)

Fixed In Version: 2.5.1-54
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2006-05-31 09:45:41 UTC

Attachments (Terms of Use)

Description David Howells 2006-04-21 11:52:13 UTC
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 12:02:17 UTC
Thanks for catching it.

Comment 2 Tim Waugh 2006-05-21 09:44:52 UTC
*** Bug 192579 has been marked as a duplicate of this bug. ***

Comment 3 Ingo van Lil 2006-05-31 07:40:08 UTC
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 09:45:41 UTC
Fixed in Fedora Core devel.

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