mirror of
https://github.com/golang/go
synced 2024-10-06 08:00:07 +00:00
internal/poll: use atomic.Bool in DupCloseOnExec
Invert the meaning of the var to make use of the zero value. Change-Id: If18db09896a67cb37cb3fe7dc0fb3493c6050a87 Reviewed-on: https://go-review.googlesource.com/c/go/+/463847 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
2a3c695c4b
commit
3c529c5367
|
@ -688,13 +688,12 @@ func (fd *FD) Fstat(s *syscall.Stat_t) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// tryDupCloexec indicates whether F_DUPFD_CLOEXEC should be used.
|
// dupCloexecUnsupported indicates whether F_DUPFD_CLOEXEC is supported by the kernel.
|
||||||
// If the kernel doesn't support it, this is set to 0.
|
var dupCloexecUnsupported atomic.Bool
|
||||||
var tryDupCloexec = int32(1)
|
|
||||||
|
|
||||||
// DupCloseOnExec dups fd and marks it close-on-exec.
|
// DupCloseOnExec dups fd and marks it close-on-exec.
|
||||||
func DupCloseOnExec(fd int) (int, string, error) {
|
func DupCloseOnExec(fd int) (int, string, error) {
|
||||||
if syscall.F_DUPFD_CLOEXEC != 0 && atomic.LoadInt32(&tryDupCloexec) == 1 {
|
if syscall.F_DUPFD_CLOEXEC != 0 && !dupCloexecUnsupported.Load() {
|
||||||
r0, e1 := fcntl(fd, syscall.F_DUPFD_CLOEXEC, 0)
|
r0, e1 := fcntl(fd, syscall.F_DUPFD_CLOEXEC, 0)
|
||||||
if e1 == nil {
|
if e1 == nil {
|
||||||
return r0, "", nil
|
return r0, "", nil
|
||||||
|
@ -704,7 +703,7 @@ func DupCloseOnExec(fd int) (int, string, error) {
|
||||||
// Old kernel, or js/wasm (which returns
|
// Old kernel, or js/wasm (which returns
|
||||||
// ENOSYS). Fall back to the portable way from
|
// ENOSYS). Fall back to the portable way from
|
||||||
// now on.
|
// now on.
|
||||||
atomic.StoreInt32(&tryDupCloexec, 0)
|
dupCloexecUnsupported.Store(true)
|
||||||
default:
|
default:
|
||||||
return -1, "fcntl", e1
|
return -1, "fcntl", e1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue