Closed MrDrMcCoy closed 6 months ago
Two things to consider:
-Dread
to read devices, like grep does, but by default. GNU grep hangs on named pipes when not in use, which is super annoying (some people figured this out after much frustration apparently).There are different approaches possible, each with some caveats:
stat
returns zero size), even when special (like proc/mount)-Dread
to read special files (like proc/mount)-Dread
to read special onesThe following table clarifies when a search is performed. Note that GNU/BSD grep have changed over the years on how special files are dealt with e.g. when recursing open them as nonblocking.
Searching depends on Recurse, -Dread, Regular File if the regular file is Empty. For ugrep 4.5 we have:
Note that Recurse means option -r
or if no target are specified. Searching a dir as a target is not recursing.
An alternative approach is to perform a search for scenario N N Y Y with the possibility of getting blocked, so the recursive case Y N Y Y opens the file nonblocking. Likewise for N Y Y Y and Y Y Y Y.
The first two red N in the table describe your case. The first without -Dread which ugrep does not set by default, but GNU grep does, and the second is with -Dread. The second red N should really be a Y actually. So this should be changed in the next release.
Perhaps the Alternative in this table is preferable:
When recursing we never block. When not recursing we do not block on empty files (procfs files) unless -Dread
is specified to read them. With these parameters, with or without -Dread
, the proc/mounts is always searched.
Finishing up work on release 5 to include the proc FS handling changes in the Alternative table above, pending testing.
Thanks so much for this work!
When I want to see mount options for a filesystem, I typically query
/proc/mounts
like so:This does not work with
ugrep
, which returns nothing and exits with a status of1
for the same query:However, it returns the results as expected when
cat
abuse is introduced:Shell redirection also yields results as expected: