Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails grepping /proc/cpuinfo due to mmap #55

Closed
lespea opened this issue Sep 24, 2016 · 2 comments
Closed

Fails grepping /proc/cpuinfo due to mmap #55

lespea opened this issue Sep 24, 2016 · 2 comments

Comments

@lespea
Copy link

lespea commented Sep 24, 2016

Not sure if this is expected behavior or not. Using 0.1.17.

rg -i mhz /proc/cpuinfo --debug
DEBUG:rg::args: will try to use memory maps
DEBUG:grep::search: regex ast:
Literal {
    chars: [
        'm',
        'h',
        'z'
    ],
    casei: true
}
DEBUG:grep::literals: literal prefixes detected: Literals { lits: [Complete(MHZ), Complete(mHZ), Complete(MhZ), Complete(mhZ), Complete(MHz), Complete(mHz), Complete(Mhz), Complete(mhz)], limit_size: 250, limit_class: 10 }
FAIL: 1
rg -i mhz /proc/cpuinfo --no-mmap
8:cpu MHz       : 1284.832
35:cpu MHz      : 1216.351
62:cpu MHz      : 1200.036
89:cpu MHz      : 1199.835
116:cpu MHz     : 1200.238
143:cpu MHz     : 1199.835
170:cpu MHz     : 1205.474
197:cpu MHz     : 1228.033
224:cpu MHz     : 1267.712
251:cpu MHz     : 1199.835
278:cpu MHz     : 1199.835
305:cpu MHz     : 1209.301
grep -i mhz /proc/cpuinfo
cpu MHz     : 1199.835
cpu MHz     : 1199.835
cpu MHz     : 1199.835
cpu MHz     : 1202.252
cpu MHz     : 1199.633
cpu MHz     : 1199.835
cpu MHz     : 1219.573
cpu MHz     : 1200.036
cpu MHz     : 1199.633
cpu MHz     : 1213.128
cpu MHz     : 1199.835
cpu MHz     : 1217.358
@BurntSushi
Copy link
Owner

This is an interesting one. /proc/cpuinfo advertises itself as a regular empty file, but it appears that it cannot be memory mapped. rg will try to use memory maps for single file searches, but since /proc/cpuinfo is an empty file, it reports no matches.

If you pass --no-mmap to rg, then searching works.

(ag has the same failure mode.)

@BurntSushi
Copy link
Owner

Duh. I know. If a file has size 0, then just fall back to regular read calls.

amsharma91 added a commit to amsharma91/ripgrep that referenced this issue Sep 27, 2016
Files like /proc/cpuinfo will advertise themselves as a normal file with
size 0. Normally, this isn't a problem, but if ripgrep decides to use a
memory map, it skipped searching if the file was empty since it's an error
to memory map an empty file. Instead of returning 0, we should just fall
back to standard read calls.

Fixes BurntSushi#55.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants