summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2017-03-21 10:23:08 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2017-03-21 20:01:23 +0000
commit0ebaca6ba27534add5930a95acffa9acff182e2b (patch)
treef77906c731c0947f4c483cd8db2698980d6ccbf6
parent051cbf3f3720086ec6d3fd159a234bae3ffd12ef (diff)
downloadgo-git-0ebaca6ba27534add5930a95acffa9acff182e2b.tar.gz
syscall, os: use pipe2 syscall on FreeBSD instead of pipe
The pipe2 syscall exists in all officially supported FreeBSD versions: 10, 11 and future 12. The pipe syscall no longer exists in 11 and 12. To build and run Go on these versions, kernel needs COMPAT_FREEBSD10 option. Based on Gleb Smirnoff's https://golang.org/cl/38422 Fixes #18854 Change-Id: I8e201ee1b15dca10427c3093b966025d160aaf61 Reviewed-on: https://go-review.googlesource.com/38426 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/os/pipe_bsd.go2
-rw-r--r--src/os/pipe_freebsd.go20
-rw-r--r--src/syscall/exec_bsd.go14
-rw-r--r--src/syscall/exec_freebsd.go9
-rw-r--r--src/syscall/forkpipe_bsd.go20
-rw-r--r--src/syscall/syscall_freebsd.go15
-rw-r--r--src/syscall/zsyscall_freebsd_386.go6
-rw-r--r--src/syscall/zsyscall_freebsd_amd64.go6
-rw-r--r--src/syscall/zsyscall_freebsd_arm.go6
9 files changed, 67 insertions, 31 deletions
diff --git a/src/os/pipe_bsd.go b/src/os/pipe_bsd.go
index 58cafcc999..ffd201cf45 100644
--- a/src/os/pipe_bsd.go
+++ b/src/os/pipe_bsd.go
@@ -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 darwin dragonfly freebsd nacl netbsd openbsd solaris
+// +build darwin dragonfly nacl netbsd openbsd solaris
package os
diff --git a/src/os/pipe_freebsd.go b/src/os/pipe_freebsd.go
new file mode 100644
index 0000000000..06723729f1
--- /dev/null
+++ b/src/os/pipe_freebsd.go
@@ -0,0 +1,20 @@
+// Copyright 2017 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 os
+
+import "syscall"
+
+// Pipe returns a connected pair of Files; reads from r return bytes written to w.
+// It returns the files and an error, if any.
+func Pipe() (r *File, w *File, err error) {
+ var p [2]int
+
+ e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
+ if e != nil {
+ return nil, nil, NewSyscallError("pipe", e)
+ }
+
+ return newFile(uintptr(p[0]), "|0", true), newFile(uintptr(p[1]), "|1", true), nil
+}
diff --git a/src/syscall/exec_bsd.go b/src/syscall/exec_bsd.go
index 31a4099559..730b63d1e5 100644
--- a/src/syscall/exec_bsd.go
+++ b/src/syscall/exec_bsd.go
@@ -256,17 +256,3 @@ childerror:
RawSyscall(SYS_EXIT, 253, 0, 0)
}
}
-
-// Try to open a pipe with O_CLOEXEC set on both file descriptors.
-func forkExecPipe(p []int) error {
- err := Pipe(p)
- if err != nil {
- return err
- }
- _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC)
- if err != nil {
- return err
- }
- _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
- return err
-}
diff --git a/src/syscall/exec_freebsd.go b/src/syscall/exec_freebsd.go
new file mode 100644
index 0000000000..1654b4ba2a
--- /dev/null
+++ b/src/syscall/exec_freebsd.go
@@ -0,0 +1,9 @@
+// Copyright 2017 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
+
+func forkExecPipe(p []int) error {
+ return Pipe2(p, O_CLOEXEC)
+}
diff --git a/src/syscall/forkpipe_bsd.go b/src/syscall/forkpipe_bsd.go
new file mode 100644
index 0000000000..d41807220a
--- /dev/null
+++ b/src/syscall/forkpipe_bsd.go
@@ -0,0 +1,20 @@
+// Copyright 2011 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.
+
+// +build darwin dragonfly netbsd openbsd
+
+package syscall
+
+func forkExecPipe(p []int) error {
+ err := Pipe(p)
+ if err != nil {
+ return err
+ }
+ _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC)
+ if err != nil {
+ return err
+ }
+ _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
+ return err
+}
diff --git a/src/syscall/syscall_freebsd.go b/src/syscall/syscall_freebsd.go
index 4dc07fe3c8..e4cc621f9a 100644
--- a/src/syscall/syscall_freebsd.go
+++ b/src/syscall/syscall_freebsd.go
@@ -66,14 +66,21 @@ func direntNamlen(buf []byte) (uint64, bool) {
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
}
-//sysnb pipe() (r int, w int, err error)
+func Pipe(p []int) error {
+ return Pipe2(p, 0)
+}
+
+//sysnb pipe2(p *[2]_C_int, flags int) (err error)
-func Pipe(p []int) (err error) {
+func Pipe2(p []int, flags int) error {
if len(p) != 2 {
return EINVAL
}
- p[0], p[1], err = pipe()
- return
+ var pp [2]_C_int
+ err := pipe2(&pp, flags)
+ p[0] = int(pp[0])
+ p[1] = int(pp[1])
+ return err
}
func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) {
diff --git a/src/syscall/zsyscall_freebsd_386.go b/src/syscall/zsyscall_freebsd_386.go
index 5c22deb181..8f3da43b64 100644
--- a/src/syscall/zsyscall_freebsd_386.go
+++ b/src/syscall/zsyscall_freebsd_386.go
@@ -261,10 +261,8 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func pipe() (r int, w int, err error) {
- r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
- r = int(r0)
- w = int(r1)
+func pipe2(p *[2]_C_int, flags int) (err error) {
+ _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
if e1 != 0 {
err = errnoErr(e1)
}
diff --git a/src/syscall/zsyscall_freebsd_amd64.go b/src/syscall/zsyscall_freebsd_amd64.go
index eeabf57921..7a6d6a685a 100644
--- a/src/syscall/zsyscall_freebsd_amd64.go
+++ b/src/syscall/zsyscall_freebsd_amd64.go
@@ -261,10 +261,8 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func pipe() (r int, w int, err error) {
- r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
- r = int(r0)
- w = int(r1)
+func pipe2(p *[2]_C_int, flags int) (err error) {
+ _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
if e1 != 0 {
err = errnoErr(e1)
}
diff --git a/src/syscall/zsyscall_freebsd_arm.go b/src/syscall/zsyscall_freebsd_arm.go
index b7592f1068..a9da768352 100644
--- a/src/syscall/zsyscall_freebsd_arm.go
+++ b/src/syscall/zsyscall_freebsd_arm.go
@@ -261,10 +261,8 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func pipe() (r int, w int, err error) {
- r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
- r = int(r0)
- w = int(r1)
+func pipe2(p *[2]_C_int, flags int) (err error) {
+ _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
if e1 != 0 {
err = errnoErr(e1)
}