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-on: https://go-review.googlesource.com/c/go/+/794140
Reviewed-by: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.