unix: fix darwin pipe implementation

The raw syscall returned the two pipes whereas the libc call
takes a pointer to a location to write the two pipes.
When we switched over from raw syscalls to libc calls, this
change in behavior was missed.

Fixes golang/go#43498

Change-Id: Icee2204dcb8be8fc94be0df106e1ff061cafa446
Reviewed-on: https://go-review.googlesource.com/c/sys/+/281432
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Keith Randall
2021-01-04 20:47:34 +00:00
parent 2d18734c60
commit 6f8348627a
6 changed files with 49 additions and 18 deletions
+36
View File
@@ -896,3 +896,39 @@ func chtmpdir(t *testing.T) func() {
os.RemoveAll(d)
}
}
func TestPipe(t *testing.T) {
const s = "hello"
var pipes [2]int
unix.Pipe(pipes[:])
r := pipes[0]
w := pipes[1]
go func() {
n, err := unix.Write(w, []byte(s))
if err != nil {
t.Fatalf("bad write: %s\n", err)
}
if n != len(s) {
t.Fatalf("bad write count: %d\n", n)
}
err = unix.Close(w)
if err != nil {
t.Fatalf("bad close: %s\n", err)
}
}()
var buf [10 + len(s)]byte
n, err := unix.Read(r, buf[:])
if err != nil {
t.Fatalf("bad read: %s\n", err)
}
if n != len(s) {
t.Fatalf("bad read count: %d\n", n)
}
if string(buf[:n]) != s {
t.Fatalf("bad contents: %s\n", string(buf[:n]))
}
err = unix.Close(r)
if err != nil {
t.Fatalf("bad close: %s\n", err)
}
}