From b8b9e83ec7a92498c2c69a1a963c31983d303e21 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 9 Aug 2022 17:45:01 +0200 Subject: [PATCH] internal/poll: remove fallback path in accept Support for operating system versions requiring the fallback to CloseOnExec/SetNonblock was dropped from recent Go versions. The minimum Linux kernel version is 2.6.32 as of Go 1.18. FreeBSD 10 is no longer supported as of Go 1.13. Follows a similar change for net.sysSocket in CL 403634 and syscall.Socket in CL 422374. For #45964 Change-Id: I60848415742a1d8204e1fda585462ff35ad6722f Reviewed-on: https://go-review.googlesource.com/c/go/+/422375 Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Auto-Submit: Tobias Klauser Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor --- src/internal/poll/sock_cloexec.go | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/internal/poll/sock_cloexec.go b/src/internal/poll/sock_cloexec.go index e106b28377..4fb9f004bb 100644 --- a/src/internal/poll/sock_cloexec.go +++ b/src/internal/poll/sock_cloexec.go @@ -15,36 +15,8 @@ import "syscall" // descriptor as nonblocking and close-on-exec. func accept(s int) (int, syscall.Sockaddr, string, error) { ns, sa, err := Accept4Func(s, syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC) - // On Linux the accept4 system call was introduced in 2.6.28 - // kernel and on FreeBSD it was introduced in 10 kernel. If we - // get an ENOSYS error on both Linux and FreeBSD, or EINVAL - // error on Linux, fall back to using accept. - switch err { - case nil: - return ns, sa, "", nil - default: // errors other than the ones listed - return -1, sa, "accept4", err - case syscall.ENOSYS: // syscall missing - case syscall.EINVAL: // some Linux use this instead of ENOSYS - case syscall.EACCES: // some Linux use this instead of ENOSYS - case syscall.EFAULT: // some Linux use this instead of ENOSYS - } - - // See ../syscall/exec_unix.go for description of ForkLock. - // It is probably okay to hold the lock across syscall.Accept - // because we have put fd.sysfd into non-blocking mode. - // However, a call to the File method will put it back into - // blocking mode. We can't take that risk, so no use of ForkLock here. - ns, sa, err = AcceptFunc(s) - if err == nil { - syscall.CloseOnExec(ns) - } if err != nil { - return -1, nil, "accept", err - } - if err = syscall.SetNonblock(ns, true); err != nil { - CloseFunc(ns) - return -1, nil, "setnonblock", err + return -1, sa, "accept4", err } return ns, sa, "", nil } -- 2.50.0