Date: Sun, 25 Oct 2015 22:52:20 +0100 From: Jilles Tjoelker <jilles@stack.nl> To: Ivan Radovanovic <radovanovic@gmail.com> Cc: freebsd-hackers@FreeBSD.org Subject: Re: Opening file to be used with kevent Message-ID: <20151025215220.GA48903@stack.nl> In-Reply-To: <562D30E7.50300@gmail.com> References: <562D30E7.50300@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20151025215220.GA48903>