]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: remove cloexecSocket fallback path
authorTobias Klauser <tklauser@distanz.ch>
Wed, 10 Aug 2022 09:37:22 +0000 (11:37 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 19 Aug 2022 16:27:36 +0000 (16:27 +0000)
Support for Linux kernel versions requiring the fallback to CloseOnExec
was dropped from recent Go versions. The minimum Linux kernel version is
2.6.32 as of Go 1.18. The SOCK_CLOEXEC flag for the socket syscall is
supported since kernel version 2.6.27.

Follows a similar change for net.sysSocket in CL 403634.

For #45964

Change-Id: I8b6311f07c4ed7900a9af3ecb2e146c49db08665
Reviewed-on: https://go-review.googlesource.com/c/go/+/422374
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>

src/syscall/lsf_linux.go
src/syscall/netlink_linux.go
src/syscall/sock_cloexec_linux.go [deleted file]

index 28e96d54e6a195ecb57e1d16511eea6fc73b2bfb..838acc5fb1944e76677b3c879ae79f866b8c29e6 100644 (file)
@@ -48,7 +48,7 @@ type iflags struct {
 
 // Deprecated: Use golang.org/x/net/bpf instead.
 func SetLsfPromisc(name string, m bool) error {
-       s, e := cloexecSocket(AF_INET, SOCK_DGRAM, 0)
+       s, e := Socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0)
        if e != nil {
                return e
        }
index 2d810705bf1bcd38f162bf5a639244619af6a163..e976c70ef1670ae97987a20733d4e9fefeb0c67e 100644 (file)
@@ -50,7 +50,7 @@ func newNetlinkRouteRequest(proto, seq, family int) []byte {
 // NetlinkRIB returns routing information base, as known as RIB, which
 // consists of network facility information, states and parameters.
 func NetlinkRIB(proto, family int) ([]byte, error) {
-       s, err := cloexecSocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)
+       s, err := Socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE)
        if err != nil {
                return nil, err
        }
diff --git a/src/syscall/sock_cloexec_linux.go b/src/syscall/sock_cloexec_linux.go
deleted file mode 100644 (file)
index 600cf25..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package syscall
-
-// This is a stripped down version of sysSocket from net/sock_cloexec.go.
-func cloexecSocket(family, sotype, proto int) (int, error) {
-       s, err := Socket(family, sotype|SOCK_CLOEXEC, proto)
-       switch err {
-       case nil:
-               return s, nil
-       default:
-               return -1, err
-       case EINVAL:
-       }
-
-       ForkLock.RLock()
-       s, err = Socket(family, sotype, proto)
-       if err == nil {
-               CloseOnExec(s)
-       }
-       ForkLock.RUnlock()
-       if err != nil {
-               Close(s)
-               return -1, err
-       }
-       return s, nil
-}