From fe196a064e588d33922c1898bb3b688c5fbf3e2d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 10 Aug 2022 11:37:22 +0200 Subject: [PATCH] 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 TryBot-Result: Gopher Robot Auto-Submit: Tobias Klauser Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser --- src/syscall/lsf_linux.go | 2 +- src/syscall/netlink_linux.go | 2 +- src/syscall/sock_cloexec_linux.go | 29 ----------------------------- 3 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 src/syscall/sock_cloexec_linux.go diff --git a/src/syscall/lsf_linux.go b/src/syscall/lsf_linux.go index 28e96d54e6a..838acc5fb19 100644 --- a/src/syscall/lsf_linux.go +++ b/src/syscall/lsf_linux.go @@ -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 } diff --git a/src/syscall/netlink_linux.go b/src/syscall/netlink_linux.go index 2d810705bf1..e976c70ef16 100644 --- a/src/syscall/netlink_linux.go +++ b/src/syscall/netlink_linux.go @@ -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 index 600cf25c150..00000000000 --- a/src/syscall/sock_cloexec_linux.go +++ /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 -}