]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "internal/poll: remove fallback path in accept"
authorIan Lance Taylor <iant@golang.org>
Tue, 6 Jun 2023 17:39:21 +0000 (17:39 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 7 Jun 2023 18:23:55 +0000 (18:23 +0000)
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 <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

src/internal/poll/sock_cloexec.go

index f5be2aa5f2634ed24efed3eb338b93d2f361aa01..cb40f4713645302877a1d9b69aa34ec17a21a573 100644 (file)
@@ -15,8 +15,36 @@ 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)
-       if err != nil {
+       // 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 ns, sa, "", nil
 }