1
0
mirror of https://github.com/golang/go synced 2024-11-22 22:00:02 -07:00

syscall: remove cloexecSocket fallback path

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>
This commit is contained in:
Tobias Klauser 2022-08-10 11:37:22 +02:00 committed by Gopher Robot
parent 5729419420
commit fe196a064e
3 changed files with 2 additions and 31 deletions

View File

@ -48,7 +48,7 @@ type iflags struct {
// Deprecated: Use golang.org/x/net/bpf instead. // Deprecated: Use golang.org/x/net/bpf instead.
func SetLsfPromisc(name string, m bool) error { 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 { if e != nil {
return e return e
} }

View File

@ -50,7 +50,7 @@ func newNetlinkRouteRequest(proto, seq, family int) []byte {
// NetlinkRIB returns routing information base, as known as RIB, which // NetlinkRIB returns routing information base, as known as RIB, which
// consists of network facility information, states and parameters. // consists of network facility information, states and parameters.
func NetlinkRIB(proto, family int) ([]byte, error) { 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -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
}