[go] os: test and fix ReadDir("/dev/fd") on macOS

0 views
Skip to first unread message

Russ Cox (Gerrit)

unread,
Jun 25, 2026, 2:31:36 PM (2 days ago) Jun 25
to Russ Cox, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Damien Neil, golang...@luci-project-accounts.iam.gserviceaccount.com, Ian Lance Taylor, Brad Fitzpatrick, Gopher Robot, golang-co...@googlegroups.com

Russ Cox submitted the change

Change information

Commit message:
os: test and fix ReadDir("/dev/fd") on macOS

ReadDir("/dev/fd") on macOS fails during tests with EBADF.
There is a kernel bug where fstat(N) works but lstat("/dev/fd/N")
and fstatat(open("/dev/fd"), "N") both fail when N is a kqueue fd.
Treat EBADF the same way as ENOENT for purposes of continuing
the ReadDir loop. The effect will be that we don't report the open
kqueue fd, but at least we will report everything else.

While we are here, change the lstatat error path to include
the name being lstat'ed, even though it still has operation "fstatat".
This changes the error from:

read_test.go:157: fstatat /dev/fd: bad file descriptor

to:

read_test.go:157: fstatat /dev/fd/3: bad file descriptor

which is more helpful. It also more closely matches older
Go versions that failed with:

read_test.go:157: lstat /dev/fd/3: bad file descriptor

Of course, with the EBADF workaround we should no longer
see any form of this message, but clean it up anyway.

For #80143.
Change-Id: If3e954b523f50d4c3d7046e5401c4b1a6a6a6964
Reviewed-by: Ian Lance Taylor <ia...@golang.org>
Reviewed-by: Damien Neil <dn...@google.com>
Files:
  • M src/os/dir_darwin.go
  • M src/os/read_test.go
  • M src/os/statat_unix.go
Change size: S
Delta: 3 files changed, 27 insertions(+), 1 deletion(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: If3e954b523f50d4c3d7046e5401c4b1a6a6a6964
Gerrit-Change-Number: 794140
Gerrit-PatchSet: 7
Gerrit-Owner: Russ Cox <r...@golang.org>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages