From owner-freebsd-hackers@freebsd.org Sun Oct 25 21:52:24 2015 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DA1678466 for ; Sun, 25 Oct 2015 21:52:24 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id A393613AB for ; Sun, 25 Oct 2015 21:52:24 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id EBF15358C5A; Sun, 25 Oct 2015 22:52:20 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id CA8BE28494; Sun, 25 Oct 2015 22:52:20 +0100 (CET) Date: Sun, 25 Oct 2015 22:52:20 +0100 From: Jilles Tjoelker To: Ivan Radovanovic Cc: freebsd-hackers@FreeBSD.org Subject: Re: Opening file to be used with kevent Message-ID: <20151025215220.GA48903@stack.nl> References: <562D30E7.50300@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <562D30E7.50300@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Oct 2015 21:52:24 -0000 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