Skip to content

Commit 7f26e9e

Browse files
ianlancetaylorgopherbot
authored andcommitted
Revert "internal/poll: remove fallback path in accept"
This reverts CL 422375. Reason for revert: We still need the fallback path on Solaris. For #45964 For #59359 Change-Id: Ie598b9ef180708fb157080015aee44f67f6737c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/501275 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 3d78c73 commit 7f26e9e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/internal/poll/sock_cloexec.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,36 @@ 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-
if err != nil {
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
1926
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+
}
42+
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
2048
}
2149
return ns, sa, "", nil
2250
}

0 commit comments

Comments
 (0)