Skip to content

Commit b8b9e83

Browse files
tklausergopherbot
authored andcommitted
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 <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
1 parent 021fd86 commit b8b9e83

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

Diff for: src/internal/poll/sock_cloexec.go

+1-29
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,8 @@ import "syscall"
1515
// descriptor as nonblocking and close-on-exec.
1616
func accept(s int) (int, syscall.Sockaddr, string, error) {
1717
ns, sa, err := Accept4Func(s, syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC)
18-
// On Linux the accept4 system call was introduced in 2.6.28
19-
// kernel and on FreeBSD it was introduced in 10 kernel. If we
20-
// get an ENOSYS error on both Linux and FreeBSD, or EINVAL
21-
// error on Linux, fall back to using accept.
22-
switch err {
23-
case nil:
24-
return ns, sa, "", nil
25-
default: // errors other than the ones listed
26-
return -1, sa, "accept4", err
27-
case syscall.ENOSYS: // syscall missing
28-
case syscall.EINVAL: // some Linux use this instead of ENOSYS
29-
case syscall.EACCES: // some Linux use this instead of ENOSYS
30-
case syscall.EFAULT: // some Linux use this instead of ENOSYS
31-
}
32-
33-
// See ../syscall/exec_unix.go for description of ForkLock.
34-
// It is probably okay to hold the lock across syscall.Accept
35-
// because we have put fd.sysfd into non-blocking mode.
36-
// However, a call to the File method will put it back into
37-
// blocking mode. We can't take that risk, so no use of ForkLock here.
38-
ns, sa, err = AcceptFunc(s)
39-
if err == nil {
40-
syscall.CloseOnExec(ns)
41-
}
4218
if err != nil {
43-
return -1, nil, "accept", err
44-
}
45-
if err = syscall.SetNonblock(ns, true); err != nil {
46-
CloseFunc(ns)
47-
return -1, nil, "setnonblock", err
19+
return -1, sa, "accept4", err
4820
}
4921
return ns, sa, "", nil
5022
}

0 commit comments

Comments
 (0)