Bug 189580

Summary: grep -D skip is not honoured
Product: [Fedora] Fedora Reporter: David Howells <dhowells>
Component: grepAssignee: Tim Waugh <twaugh>
Status: CLOSED RAWHIDE QA Contact: Mike McLean <mikem>
Severity: medium Docs Contact:
Priority: medium    
Version: 5CC: inguin, jreiser
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 2.5.1-54 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-05-31 09:45:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 150223    

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): 
 
grep-2.5.1-52.2 
 
How reproducible: 
 
100% 
 
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 
./y:hello 
[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 
file. 
 
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
http://lists.gnu.org/archive/html/grep-commit/2004-11/msg00095.html.

Comment 4 Tim Waugh 2006-05-31 09:45:41 UTC
Fixed in Fedora Core devel.