does not work for files in /proc #446

Open
bugfood opened this Issue Jul 15, 2014 · 2 comments

Comments

Projects
None yet
3 participants

bugfood commented Jul 15, 2014

Hi,

Thanks for a nice tool. I've gotten used to using it instead of grep all the time, but I got caught up when searching a file in /proc.

chickey@corey:~$ grep Dirty /proc/meminfo 
Dirty:               324 kB
chickey@corey:~$ ag Dirty /proc/meminfo 
chickey@corey:~$ ag -D Dirty /proc/meminfo 
DEBUG: Found user's home dir: /home/chickey
DEBUG: Skipping ignore file /home/chickey/.agignore
DEBUG: added regex ignore pattern *.swp
DEBUG: Query is Dirty
DEBUG: PCRE Version: 8.31 2012-07-06
DEBUG: Using 3 workers
DEBUG: searching path /proc/meminfo for Dirty
DEBUG: Skipping ignore file /proc/meminfo/.agignore
DEBUG: Skipping ignore file /proc/meminfo/.gitignore
DEBUG: Skipping ignore file /proc/meminfo/.git/info/exclude
DEBUG: Skipping ignore file /proc/meminfo/.hgignore
DEBUG: Skipping svn ignore file /proc/meminfo/.svn/dir-prop-base
DEBUG: File /proc/meminfo is empty, skipping.
DEBUG: Worker finished.
DEBUG: Worker finished.
DEBUG: Worker finished.

This seems to be happening because these files are reported by the OS as having 0 length, so ag skips them. I don't have any suggestion other than to remove the check; unfortunately, if I try that, mmap fails afterward, so a fix for this is apparently less simple.

Thanks,
Corey

It seems that the procfs does not support the mmap operation. The only operations supported are the ones defines in the structure proc_mem_operations.
A possible fix would be to check the errno set by mmap after it fails (which is ENODEV for devices that do not support mmap) and fallback to reading into a buffer.

Hubbitus commented Nov 2, 2016

It the same on block devices:

# ag -DFau --search-binary test /dev/sdc2
DEBUG: global core.excludesfile: /root/.config/git/ignore
DEBUG: Skipping ignore file /root/.config/git/ignore: not readable
DEBUG: Query is test
DEBUG: PCRE Version: 8.39 2016-06-14
DEBUG: Using 7 workers
DEBUG: Thread 0 set to CPU 0
DEBUG: Thread 1 set to CPU 1
DEBUG: Worker 0 started
DEBUG: Thread 2 set to CPU 2
DEBUG: Worker 2 started
DEBUG: Thread 3 set to CPU 3
DEBUG: Thread 4 set to CPU 4
DEBUG: Worker 4 started
DEBUG: Thread 5 set to CPU 5
DEBUG: Worker 5 started
DEBUG: Thread 6 set to CPU 6
DEBUG: searching path /dev/sdc2 for test
DEBUG: Skipping ignore file /dev/sdc2/.agignore: not readable
DEBUG: Skipping ignore file /dev/sdc2/.gitignore: not readable
DEBUG: Skipping ignore file /dev/sdc2/.git/info/exclude: not readable
DEBUG: Skipping ignore file /dev/sdc2/.hgignore: not readable
DEBUG: Skipping svn ignore file /dev/sdc2/.svn/dir-prop-base
DEBUG: Skipping /dev/sdc2: file is empty.
DEBUG: Worker 3 started
DEBUG: Worker 3 finished.
DEBUG: Worker 1 started
DEBUG: Worker 1 finished.
DEBUG: Worker 0 finished.
DEBUG: Worker 2 finished.
DEBUG: Worker 4 finished.
DEBUG: Worker 5 finished.
DEBUG: Worker 6 started
DEBUG: Worker 6 finished.

fgrep -a test /dev/sdc2 return many results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment