Opening file to be used with kevent

Jilles Tjoelker jilles at stack.nl
Sun Oct 25 21:52:24 UTC 2015


On Sun, Oct 25, 2015 at 08:43:35PM +0100, Ivan Radovanovic wrote:
> What are recommended flags to use when opening file descriptor to be 
> used later with kevent(2)?

> I was thinking to specify O_RDONLY but I guess that would prevent any 
> other process from opening file with O_EXCL (and I don't care about file 
> contents anyway, I just want to be notified when file is changed). 

O_RDONLY does not prevent any other process from doing anything to the
file, except non-forced unmounting the filesystem it is on, like all
open modes do.

O_WRONLY and O_RDWR do prevent other processes from doing something:
files open for writing cannot be executed as a program (execve(2) or
similar will fail with [ETXTBSY]).

> Apparently Darwing has O_EVTONLY for this purpose, so I am wondering if 
> FreeBSD has something equivalent (or what would be the weakest mode to 
> pass to open(2))?

There is no equivalent but there are O_RDONLY and O_EXEC.

I think the main issue to deal with is not permissions but unmounts. The
approach with open(2) and kevent(2) prevents unmounting volumes if some
application is monitoring a file on them. Ideally, monitoring a file
would not prevent an unmount, and the unmount would generate a final
event that the file is no longer accessible. On the other hand, getting
notifications about the file contents does not make much sense if you
are not allowed to read them.

-- 
Jilles Tjoelker


More information about the freebsd-hackers mailing list