Skip to content

Commit

Permalink
net, internal/poll, net/internal/socktest: set SOCK_{CLOEXEC,NONBLOCK…
Browse files Browse the repository at this point in the history
…} atomically on NetBSD

NetBSD supports the SOCK_CLOEXEC and SOCK_NONBLOCK flags to the socket
syscall since version 6.0. The same version also introduced the paccept
syscall which can be used to implement syscall.Accept4.

Follows CL 40895

Change-Id: I9e4e1829b0382744c7799f4e58929a53b4e193f7
Reviewed-on: https://go-review.googlesource.com/94295
Run-TryBot: Tobias Klauser <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Benny Siegert <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
tklauser committed Feb 15, 2018
1 parent 33eb063 commit 9542ba6
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/internal/poll/hook_cloexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build dragonfly freebsd linux
// +build dragonfly freebsd linux netbsd

package poll

Expand Down
2 changes: 1 addition & 1 deletion src/internal/poll/sock_cloexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that
// provide a fast path for setting SetNonblock and CloseOnExec.

// +build dragonfly freebsd linux
// +build dragonfly freebsd linux netbsd

package poll

Expand Down
2 changes: 1 addition & 1 deletion src/internal/poll/sys_cloexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that do not
// provide a fast path for setting SetNonblock and CloseOnExec.

// +build darwin nacl netbsd openbsd solaris
// +build darwin nacl openbsd solaris

package poll

Expand Down
2 changes: 1 addition & 1 deletion src/net/internal/socktest/sys_cloexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build dragonfly freebsd linux
// +build dragonfly freebsd linux netbsd

package socktest

Expand Down
2 changes: 1 addition & 1 deletion src/net/main_cloexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build dragonfly freebsd linux
// +build dragonfly freebsd linux netbsd

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/sock_cloexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that
// provide a fast path for setting SetNonblock and CloseOnExec.

// +build dragonfly freebsd linux
// +build dragonfly freebsd linux netbsd

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/sys_cloexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that do not
// provide a fast path for setting SetNonblock and CloseOnExec.

// +build darwin nacl netbsd openbsd solaris
// +build darwin nacl openbsd solaris

package net

Expand Down
19 changes: 19 additions & 0 deletions src/syscall/syscall_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ func Pipe2(p []int, flags int) error {
return err
}

//sys paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error)
func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
var rsa RawSockaddrAny
var len _Socklen = SizeofSockaddrAny
nfd, err = paccept(fd, &rsa, &len, nil, flags)
if err != nil {
return
}
if len > SizeofSockaddrAny {
panic("RawSockaddrAny too small")
}
sa, err = anyToSockaddr(&rsa)
if err != nil {
Close(nfd)
nfd = 0
}
return
}

//sys getdents(fd int, buf []byte) (n int, err error)
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
return getdents(fd, buf)
Expand Down
4 changes: 4 additions & 0 deletions src/syscall/types_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,7 @@ type Termios C.struct_termios
// Sysctl

type Sysctlnode C.struct_sysctlnode

// Signals

type sigset C.sigset_t
11 changes: 11 additions & 0 deletions src/syscall/zsyscall_netbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_PACCEPT, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(unsafe.Pointer(sigmask)), uintptr(flags), 0)
nfd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func getdents(fd int, buf []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(buf) > 0 {
Expand Down
11 changes: 11 additions & 0 deletions src/syscall/zsyscall_netbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_PACCEPT, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(unsafe.Pointer(sigmask)), uintptr(flags), 0)
nfd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func getdents(fd int, buf []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(buf) > 0 {
Expand Down
11 changes: 11 additions & 0 deletions src/syscall/zsyscall_netbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_PACCEPT, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(unsafe.Pointer(sigmask)), uintptr(flags), 0)
nfd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func getdents(fd int, buf []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(buf) > 0 {
Expand Down
4 changes: 4 additions & 0 deletions src/syscall/ztypes_netbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,7 @@ type Sysctlnode struct {
X_sysctl_parent [8]byte
X_sysctl_desc [8]byte
}

type sigset struct {
X__bits [4]uint32
}
4 changes: 4 additions & 0 deletions src/syscall/ztypes_netbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,7 @@ type Sysctlnode struct {
X_sysctl_parent [8]byte
X_sysctl_desc [8]byte
}

type sigset struct {
X__bits [4]uint32
}
4 changes: 4 additions & 0 deletions src/syscall/ztypes_netbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,7 @@ type Sysctlnode struct {
X_sysctl_parent [8]byte
X_sysctl_desc [8]byte
}

type sigset struct {
X__bits [4]uint32
}

0 comments on commit 9542ba6

Please sign in to comment.