]> Cypherpunks repositories - gostls13.git/commitdiff
net: pass MSG_CMSG_CLOEXEC in ReadMsgUnix on dragonfly, netbsd and openbsd
authorTobias Klauser <tklauser@distanz.ch>
Tue, 20 Apr 2021 08:25:19 +0000 (10:25 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Tue, 20 Apr 2021 21:00:46 +0000 (21:00 +0000)
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>
src/net/unixsock_posix.go
src/net/unixsock_readmsg_cloexec.go [moved from src/net/unixsock_readmsg_posix.go with 78% similarity]
src/net/unixsock_readmsg_cmsg_cloexec.go [moved from src/net/unixsock_readmsg_linux.go with 59% similarity]
src/net/unixsock_readmsg_other.go
src/syscall/zerrors_dragonfly_amd64.go
src/syscall/zerrors_openbsd_386.go
src/syscall/zerrors_openbsd_amd64.go

index 0306b5989beabb737264864fbd3a0029a4e68788..99a89c827b8abbebf361141c42458e6c0c6c55f9 100644 (file)
@@ -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])
        }
 
similarity index 78%
rename from src/net/unixsock_readmsg_posix.go
rename to src/net/unixsock_readmsg_cloexec.go
index 07d7df5e6670d2da972816f971a26b40c650e0b2..716484cc6ce95704e6d817018f41387045a0c063 100644 (file)
@@ -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
 
similarity index 59%
rename from src/net/unixsock_readmsg_linux.go
rename to src/net/unixsock_readmsg_cmsg_cloexec.go
index 3296681017ec4dd7106847a94908204ec8d524ee..bb851b89c05bd395150e9cee60b272f2f882a076 100644 (file)
@@ -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) {}
index c8db657cd6f6a48c736682cbee213ac2b8ad2b7b..329076183aece9894ee1e539bbdb0db5cd9a2cfc 100644 (file)
@@ -9,5 +9,4 @@ package net
 
 const readMsgFlags = 0
 
-func setReadMsgCloseOnExec(oob []byte) {
-}
+func setReadMsgCloseOnExec(oob []byte) {}
index b572f44a6b92f7a3768b705b839bed0c9f602461..8ed611b3e4f2fa3a730c0dadaa7af9b6efb064ed 100644 (file)
@@ -850,6 +850,7 @@ const (
        MAP_VPAGETABLE                    = 0x2000
        MCL_CURRENT                       = 0x1
        MCL_FUTURE                        = 0x2
+       MSG_CMSG_CLOEXEC                  = 0x1000
        MSG_CTRUNC                        = 0x20
        MSG_DONTROUTE                     = 0x4
        MSG_DONTWAIT                      = 0x80
index 04d1b3f1775887342f5d1c7d7316bc8b5ad77019..a8457c6edfe8b6cde64cf49d3302b2d049c7e99e 100644 (file)
@@ -891,6 +891,7 @@ const (
        MCL_CURRENT                       = 0x1
        MCL_FUTURE                        = 0x2
        MSG_BCAST                         = 0x100
+       MSG_CMSG_CLOEXEC                  = 0x800
        MSG_CTRUNC                        = 0x20
        MSG_DONTROUTE                     = 0x4
        MSG_DONTWAIT                      = 0x80
index 923a3a47c5ebb3f8bf402e5e70b1b7befc7a75fd..eb19537a2ac9ed6104cd1e7368721edaa76315c2 100644 (file)
@@ -891,6 +891,7 @@ const (
        MCL_CURRENT                       = 0x1
        MCL_FUTURE                        = 0x2
        MSG_BCAST                         = 0x100
+       MSG_CMSG_CLOEXEC                  = 0x800
        MSG_CTRUNC                        = 0x20
        MSG_DONTROUTE                     = 0x4
        MSG_DONTWAIT                      = 0x80