diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:43 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:43 +0100 |
commit | ad47422646a18ffcb47cec916ef7393c923f2e76 (patch) | |
tree | 7c7861fb3d9539d61c1dcfd5b8dadee974c25760 /src/pkg/os/pipe_linux.go | |
parent | 2c8d5d584a79781ca41bb6f4b396893fbbac5b97 (diff) | |
parent | 04b08da9af0c450d645ab7389d1467308cfc2db8 (diff) | |
download | golang-ad47422646a18ffcb47cec916ef7393c923f2e76.tar.gz |
Merge tag 'upstream/1.1_hg20130304' into debian-sid
Upstream version 1.1~hg20130304
Diffstat (limited to 'src/pkg/os/pipe_linux.go')
-rw-r--r-- | src/pkg/os/pipe_linux.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/pkg/os/pipe_linux.go b/src/pkg/os/pipe_linux.go new file mode 100644 index 000000000..9bafad84f --- /dev/null +++ b/src/pkg/os/pipe_linux.go @@ -0,0 +1,33 @@ +// Copyright 2013 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) + // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it + // might not be implemented. + if e == syscall.ENOSYS { + // See ../syscall/exec.go for description of lock. + syscall.ForkLock.RLock() + e = syscall.Pipe(p[0:]) + if e != nil { + syscall.ForkLock.RUnlock() + return nil, nil, NewSyscallError("pipe", e) + } + syscall.CloseOnExec(p[0]) + syscall.CloseOnExec(p[1]) + syscall.ForkLock.RUnlock() + } else if e != nil { + return nil, nil, NewSyscallError("pipe2", e) + } + + return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil +} |