aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2021-04-20 10:25:19 +0200
committerTobias Klauser <tobias.klauser@gmail.com>2021-04-20 21:00:46 +0000
commit57b0d838ed2e0c128dfc480fee3b5c43309d3369 (patch)
tree427d16b4253885f734deb8473b84eb853bf6702e /src/net
parent3f8e64878a93a1b005e1ff0f2a939bab826b8b9f (diff)
downloadgo-57b0d838ed2e0c128dfc480fee3b5c43309d3369.tar.gz
go-57b0d838ed2e0c128dfc480fee3b5c43309d3369.zip
net: pass MSG_CMSG_CLOEXEC in ReadMsgUnix on dragonfly, netbsd and openbsd
Add support for passing MSG_CMSG_CLOEXEC to the recvmsg syscall on dragonfly, netbsd and openbsd. MSG_CMSG_CLOEXEC on freebsd is currently broken, see https://reviews.freebsd.org/D29328. Change-Id: Ie4c6e3cb550cd0ae32a1c2acca12edf77569e96a Reviewed-on: https://go-review.googlesource.com/c/go/+/311570 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/unixsock_posix.go2
-rw-r--r--src/net/unixsock_readmsg_cloexec.go (renamed from src/net/unixsock_readmsg_posix.go)8
-rw-r--r--src/net/unixsock_readmsg_cmsg_cloexec.go (renamed from src/net/unixsock_readmsg_linux.go)11
-rw-r--r--src/net/unixsock_readmsg_other.go3
4 files changed, 9 insertions, 15 deletions
diff --git a/src/net/unixsock_posix.go b/src/net/unixsock_posix.go
index 0306b5989b..99a89c827b 100644
--- a/src/net/unixsock_posix.go
+++ b/src/net/unixsock_posix.go
@@ -114,7 +114,7 @@ func (c *UnixConn) readFrom(b []byte) (int, *UnixAddr, error) {
func (c *UnixConn) readMsg(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err error) {
var sa syscall.Sockaddr
n, oobn, flags, sa, err = c.fd.readMsg(b, oob, readMsgFlags)
- if oobn > 0 {
+ if readMsgFlags == 0 && err == nil && oobn > 0 {
setReadMsgCloseOnExec(oob[:oobn])
}
diff --git a/src/net/unixsock_readmsg_posix.go b/src/net/unixsock_readmsg_cloexec.go
index 07d7df5e66..716484cc6c 100644
--- a/src/net/unixsock_readmsg_posix.go
+++ b/src/net/unixsock_readmsg_cloexec.go
@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build aix || darwin || dragonfly || freebsd || netbsd || openbsd || solaris
-// +build aix darwin dragonfly freebsd netbsd openbsd solaris
+//go:build aix || darwin || freebsd || solaris
+// +build aix darwin freebsd solaris
package net
-import (
- "syscall"
-)
+import "syscall"
const readMsgFlags = 0
diff --git a/src/net/unixsock_readmsg_linux.go b/src/net/unixsock_readmsg_cmsg_cloexec.go
index 3296681017..bb851b89c0 100644
--- a/src/net/unixsock_readmsg_linux.go
+++ b/src/net/unixsock_readmsg_cmsg_cloexec.go
@@ -2,16 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build linux
-// +build linux
+//go:build dragonfly || linux || netbsd || openbsd
+// +build dragonfly linux netbsd openbsd
package net
-import (
- "syscall"
-)
+import "syscall"
const readMsgFlags = syscall.MSG_CMSG_CLOEXEC
-func setReadMsgCloseOnExec(oob []byte) {
-}
+func setReadMsgCloseOnExec(oob []byte) {}
diff --git a/src/net/unixsock_readmsg_other.go b/src/net/unixsock_readmsg_other.go
index c8db657cd6..329076183a 100644
--- a/src/net/unixsock_readmsg_other.go
+++ b/src/net/unixsock_readmsg_other.go
@@ -9,5 +9,4 @@ package net
const readMsgFlags = 0
-func setReadMsgCloseOnExec(oob []byte) {
-}
+func setReadMsgCloseOnExec(oob []byte) {}