Bug 128018 - grep through > 400 files in the same directory hangs up
grep through > 400 files in the same directory hangs up
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: grep (Show other bugs)
rawhide
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
Mike McLean
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-07-16 09:19 EDT by Robert Scheck
Modified: 2007-11-30 17:10 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-07-16 10:13:48 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
strace of "grep Name *" in /usr/src/redhat/SPECS with 442 files, canceled with Strg-C (12.57 KB, text/plain)
2004-07-16 09:20 EDT, Robert Scheck
no flags Details

  None (edit)
Description Robert Scheck 2004-07-16 09:19:15 EDT
Description of problem:
If I do a grep in a directory which has for example more than 400 
files, grep simply hangs up and returns no results, even if they 
match sure.

Version-Release number of selected component (if applicable):
grep-2.5.1-29

How reproducible:
Every time, see above and below.

Steps to Reproduce:
1. For example, install all (or more than 450) Fedora Core source 
   RPMs ;-)
2. cd /usr/src/redhat/SPECS/
3. grep Name *
[4. Get the hangup]
  
Actual results:
Well, grep hangs up and doesn't speak with me - I've got a strace 
of such a grep attached.

Expected results:
Working grep, even if there are 500 or 1000 files in a directory ;-)
Comment 1 Robert Scheck 2004-07-16 09:20:20 EDT
Created attachment 101964 [details]
strace of "grep Name *" in /usr/src/redhat/SPECS with 442 files, canceled with Strg-C
Comment 2 Tim Waugh 2004-07-16 09:24:05 EDT
execve("/bin/grep", ["grep", "Name", "-", "anaconda-help.spec",
"anaconda.spec", [...]

One of your files is named '-'.  You need to use 'grep -- Name *'.
Comment 3 Robert Scheck 2004-07-16 09:33:38 EDT
Doesn't make any sense here, the problem exists further on - the 
strace result seems to be the same, too.

Hm...and the strange is, that a "grep Name *" or "grep -- Name *" 
through > 400 binary files runs immediately fine and without any 
problem:

# cd /usr/src/redhat/RPMS/i386
# 
# ls -l | wc -l
    484
# 
# grep Name *
Binary file acl-2.2.7-4.i386.rpm matches
Binary file anacron-2.3-31.i386.rpm matches
Binary file apr-0.9.4-21.i386.rpm matches
Binary file apr-devel-0.9.4-21.i386.rpm matches
Binary file apr-util-0.9.4-16.i386.rpm matches
Binary file apr-util-devel-0.9.4-16.i386.rpm matches
Binary file arpwatch-2.1a13-4.i386.rpm matches
Binary file ash-0.3.8-19.i386.rpm matches
[...]
# 

Reopening, because that behaviour simply seems wrong to me...
Comment 4 Tim Waugh 2004-07-16 09:35:39 EDT
This behaviour is correct.  Grep is doing as you asked it to.
Comment 5 Robert Scheck 2004-07-16 09:39:55 EDT
And why do neither 'grep Name *' nor 'grep -- Name *' then return any
result?!

BTW, I thought "--" is only needed, if a file/directory starts with 
a (or more) "-", not when the filename contains a "-"...
Comment 6 Tim Waugh 2004-07-16 09:58:47 EDT
Oh, it wasn't clear that '--' didn't help.

You have an actual file whose entire name is '-'.  Grep is behaving as
documented.

However, it appears to go against POSIX.  Reopening. :-(
Comment 7 Tim Waugh 2004-07-16 10:04:35 EDT
(FWIW: 'grep -- Name ./*' is the way to do this.)

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