gvansickle / ucg

UniversalCodeGrep (ucg) is an extremely fast grep-like tool specialized for searching large bodies of source code.

Home Page:https://gvansickle.github.io/ucg/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UCG may refuse to open read-only file

ZyX-I opened this issue · comments

Tried the following code:

ucg x /var/log/messages

Surprisingly it failed with

ucg: error: GetFileDescriptor(): open(/var/log/messages) failed: Operation not permitted

ag and grep are fine with opening the file. After some research I found that grep opens file with openat and flags O_RDONLY|O_NOCTTY, ag opens file with just O_RDONLY (after attempting to open it as a directory with different set of flags) and ucg tries O_RDONLY|O_NOCTTY|O_NOATIME. The last flag looks like what is causing command to fail: according to man open flag may be used either if EUID matches file owner (not true: owner is root, EUID is zyx) or calling process has CAP_FOWNER capability in … (also not true: not using capabilities anywhere in my system).

I would suggest that ucg should retry without O_NOATIME if it got EPERM.