git: 5bcccc702b29 - main - open.2: stop making impression that fd must be directory

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 16 Feb 2026 15:26:07 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=5bcccc702b29a0e173a5916b001771dd7b280c7c

commit 5bcccc702b29a0e173a5916b001771dd7b280c7c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-02-16 07:28:22 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-02-16 13:59:43 +0000

    open.2: stop making impression that fd must be directory
    
    Reviewed by:    des, rmacklem
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    Differential revision:  https://reviews.freebsd.org/D55302
---
 lib/libsys/open.2 | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/libsys/open.2 b/lib/libsys/open.2
index a0e905a8f375..b4463180e4bc 100644
--- a/lib/libsys/open.2
+++ b/lib/libsys/open.2
@@ -72,11 +72,18 @@ function is equivalent to the
 .Fn open
 function except in the case where the
 .Fa path
-specifies a relative path.
+specifies a relative path or the
+.Va O_EMPTY_PATH
+flag is specified.
 For
 .Fn openat
 and relative
 .Fa path ,
+when
+.Fa fd
+references directory and without the
+.Va O_EMPTY_PATH
+flag,
 the file to be opened is determined relative to the directory
 associated with the file descriptor
 .Fa fd
@@ -104,6 +111,14 @@ it ignores the
 .Fa fd
 argument.
 .Pp
+When
+.Fn openat
+is called with the
+.Fa fd
+argument that does not reference a directory, the call fails unless
+.Va O_EMPTY_PATH
+flag is specified, see below.
+.Pp
 In
 .Xr capsicum 4
 capability mode,
@@ -421,9 +436,11 @@ by the descriptor at the time of the
 call.
 .Pp
 .Dv O_PATH
-returns a file descriptor that can be used as a directory file descriptor for
+returns a file descriptor that can be used as the first argument for
 .Fn openat
-and other system calls taking a file descriptor argument, like
+and other filesystem-related system calls collectively named
+.Fn *at
+taking a file descriptor argument, like
 .Xr fstatat 2
 and others.
 The other functionality of the returned file descriptor is limited to