Skip to content

Commit 2730c17

Browse files
committed
syscall, os: fix FreeBSD 9 build
I broke FreeBSD 9 in https://golang.org/cl/38426 by using Pipe2. We still want to support FreeBSD 9 for one last release (Go 1.9 will be the last), and FreeBSD 9 doesn't have Pipe2. So this still uses Pipe2, but falls back to Pipe on error. Updates #18854 Updates #19072 Change-Id: I1de90fb83606c93fb84b4b86fba31e207a702835 Reviewed-on: https://go-review.googlesource.com/38430 Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent ee80afe commit 2730c17

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed

src/os/pipe_freebsd.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ func Pipe() (r *File, w *File, err error) {
1313

1414
e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
1515
if e != nil {
16-
return nil, nil, NewSyscallError("pipe", e)
16+
// Fallback support for FreeBSD 9, which lacks Pipe2.
17+
//
18+
// TODO: remove this for Go 1.10 when FreeBSD 9
19+
// is removed (Issue 19072).
20+
21+
// See ../syscall/exec.go for description of lock.
22+
syscall.ForkLock.RLock()
23+
e := syscall.Pipe(p[0:])
24+
if e != nil {
25+
syscall.ForkLock.RUnlock()
26+
return nil, nil, NewSyscallError("pipe", e)
27+
}
28+
syscall.CloseOnExec(p[0])
29+
syscall.CloseOnExec(p[1])
30+
syscall.ForkLock.RUnlock()
1731
}
1832

1933
return newFile(uintptr(p[0]), "|0", true), newFile(uintptr(p[1]), "|1", true), nil

src/syscall/exec_freebsd.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,21 @@
55
package syscall
66

77
func forkExecPipe(p []int) error {
8-
return Pipe2(p, O_CLOEXEC)
8+
err := Pipe2(p, O_CLOEXEC)
9+
if err == nil {
10+
return nil
11+
}
12+
13+
// FreeBSD 9 fallback.
14+
// TODO: remove this for Go 1.10 per Issue 19072
15+
err = Pipe(p)
16+
if err != nil {
17+
return err
18+
}
19+
_, err = fcntl(p[0], F_SETFD, FD_CLOEXEC)
20+
if err != nil {
21+
return err
22+
}
23+
_, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
24+
return err
925
}

src/syscall/syscall_freebsd.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ func direntNamlen(buf []byte) (uint64, bool) {
6666
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
6767
}
6868

69+
//sysnb pipe() (r int, w int, err error)
70+
6971
func Pipe(p []int) error {
70-
return Pipe2(p, 0)
72+
if len(p) != 2 {
73+
return EINVAL
74+
}
75+
var err error
76+
p[0], p[1], err = pipe()
77+
return err
7178
}
7279

7380
//sysnb pipe2(p *[2]_C_int, flags int) (err error)

src/syscall/zsyscall_freebsd_386.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) {
261261

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

264+
func pipe() (r int, w int, err error) {
265+
r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
266+
r = int(r0)
267+
w = int(r1)
268+
if e1 != 0 {
269+
err = errnoErr(e1)
270+
}
271+
return
272+
}
273+
274+
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
275+
264276
func pipe2(p *[2]_C_int, flags int) (err error) {
265277
_, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
266278
if e1 != 0 {

src/syscall/zsyscall_freebsd_amd64.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) {
261261

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

264+
func pipe() (r int, w int, err error) {
265+
r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
266+
r = int(r0)
267+
w = int(r1)
268+
if e1 != 0 {
269+
err = errnoErr(e1)
270+
}
271+
return
272+
}
273+
274+
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
275+
264276
func pipe2(p *[2]_C_int, flags int) (err error) {
265277
_, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
266278
if e1 != 0 {

src/syscall/zsyscall_freebsd_arm.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) {
261261

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

264+
func pipe() (r int, w int, err error) {
265+
r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
266+
r = int(r0)
267+
w = int(r1)
268+
if e1 != 0 {
269+
err = errnoErr(e1)
270+
}
271+
return
272+
}
273+
274+
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
275+
264276
func pipe2(p *[2]_C_int, flags int) (err error) {
265277
_, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
266278
if e1 != 0 {

0 commit comments

Comments
 (0)