Skip to content

Commit

Permalink
net, internal/poll, net/internal/socktest: use SOCK_{CLOEXEC,NONBLOCK…
Browse files Browse the repository at this point in the history
…} accept4/socket flags on OpenBSD

The SOCK_CLOEXEC and SOCK_NONBLOCK flags to the socket syscall and the
accept4 syscall are supported since OpenBSD 5.7.

Follows CL 40895 and CL 94295

Change-Id: Icaf35ace2ef5e73279a70d4f1a9fbf3be9371e6c
Reviewed-on: https://go-review.googlesource.com/97196
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
tklauser committed Feb 26, 2018
1 parent db7af2e commit 144bf04
Show file tree
Hide file tree
Showing 15 changed files with 65 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 netbsd
// +build dragonfly freebsd linux netbsd openbsd

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 netbsd
// +build dragonfly freebsd linux netbsd openbsd

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 openbsd solaris
// +build darwin nacl 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 netbsd
// +build dragonfly freebsd linux netbsd openbsd

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 netbsd
// +build dragonfly freebsd linux netbsd openbsd

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 netbsd
// +build dragonfly freebsd linux netbsd openbsd

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 openbsd solaris
// +build darwin nacl solaris

package net

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

//sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, 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 = accept4(fd, &rsa, &len, 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
2 changes: 2 additions & 0 deletions src/syscall/zerrors_openbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,9 @@ const (
SIOCSSPPPPARAMS = 0x80206993
SIOCSVH = 0xc02069f5
SIOCSVNETID = 0x802069a6
SOCK_CLOEXEC = 0x8000
SOCK_DGRAM = 0x2
SOCK_NONBLOCK = 0x4000
SOCK_RAW = 0x3
SOCK_RDM = 0x4
SOCK_SEQPACKET = 0x5
Expand Down
2 changes: 2 additions & 0 deletions src/syscall/zerrors_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,9 @@ const (
SIOCSSPPPPARAMS = 0x80206993
SIOCSVH = 0xc02069f5
SIOCSVNETID = 0x802069a6
SOCK_CLOEXEC = 0x8000
SOCK_DGRAM = 0x2
SOCK_NONBLOCK = 0x4000
SOCK_RAW = 0x3
SOCK_RDM = 0x4
SOCK_SEQPACKET = 0x5
Expand Down
11 changes: 11 additions & 0 deletions src/syscall/zsyscall_openbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {

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

func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 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_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {

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

func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 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_openbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {

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

func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 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
1 change: 1 addition & 0 deletions src/syscall/zsysnum_openbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
SYS_DUP2 = 90 // { int sys_dup2(int from, int to); }
SYS_NANOSLEEP = 91 // { int sys_nanosleep(const struct timespec *rqtp, \
SYS_FCNTL = 92 // { int sys_fcntl(int fd, int cmd, ... void *arg); }
SYS_ACCEPT4 = 93 // { int sys_accept4(int s, struct sockaddr *name, \
SYS___THRSLEEP = 94 // { int sys___thrsleep(const volatile void *ident, \
SYS_FSYNC = 95 // { int sys_fsync(int fd); }
SYS_SETPRIORITY = 96 // { int sys_setpriority(int which, id_t who, int prio); }
Expand Down
1 change: 1 addition & 0 deletions src/syscall/zsysnum_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
SYS_DUP2 = 90 // { int sys_dup2(int from, int to); }
SYS_NANOSLEEP = 91 // { int sys_nanosleep(const struct timespec *rqtp, \
SYS_FCNTL = 92 // { int sys_fcntl(int fd, int cmd, ... void *arg); }
SYS_ACCEPT4 = 93 // { int sys_accept4(int s, struct sockaddr *name, \
SYS___THRSLEEP = 94 // { int sys___thrsleep(const volatile void *ident, \
SYS_FSYNC = 95 // { int sys_fsync(int fd); }
SYS_SETPRIORITY = 96 // { int sys_setpriority(int which, id_t who, int prio); }
Expand Down

0 comments on commit 144bf04

Please sign in to comment.