1
0
mirror of https://github.com/golang/go synced 2024-10-04 17:21:20 -06:00

os/exec: fix plan9 build

Fixes build from https://golang.org/cl/12152

Plan 9 lacks syscall.EPIPE. I was misled by api/go1.txt and also
forgot to use the trybots. :(

Change-Id: I4982fe969ad4a8724090cb03009bfb21780d8aa7
Reviewed-on: https://go-review.googlesource.com/12153
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Brad Fitzpatrick 2015-07-13 22:13:32 -07:00
parent c218a075be
commit a74d030557
2 changed files with 30 additions and 8 deletions

View File

@ -157,6 +157,11 @@ func (c *Cmd) argv() []string {
return []string{c.Path} return []string{c.Path}
} }
// skipStdinCopyError optionally specifies a function which reports
// whether the provided the stdin copy error should be ignored.
// It is non-nil everywhere but Plan 9, which lacks EPIPE. See exec_posix.go.
var skipStdinCopyError func(error) bool
func (c *Cmd) stdin() (f *os.File, err error) { func (c *Cmd) stdin() (f *os.File, err error) {
if c.Stdin == nil { if c.Stdin == nil {
f, err = os.Open(os.DevNull) f, err = os.Open(os.DevNull)
@ -180,16 +185,9 @@ func (c *Cmd) stdin() (f *os.File, err error) {
c.closeAfterWait = append(c.closeAfterWait, pw) c.closeAfterWait = append(c.closeAfterWait, pw)
c.goroutine = append(c.goroutine, func() error { c.goroutine = append(c.goroutine, func() error {
_, err := io.Copy(pw, c.Stdin) _, err := io.Copy(pw, c.Stdin)
if skip := skipStdinCopyError; skip != nil && skip(err) {
// Ignore EPIPE errors copying to stdin if the program
// completed successfully otherwise.
// See Issue 9173.
if pe, ok := err.(*os.PathError); ok &&
pe.Op == "write" && pe.Path == "|1" &&
pe.Err == syscall.EPIPE {
err = nil err = nil
} }
if err1 := pw.Close(); err == nil { if err1 := pw.Close(); err == nil {
err = err1 err = err1
} }

24
src/os/exec/exec_posix.go Normal file
View File

@ -0,0 +1,24 @@
// Copyright 2015 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 !plan9
package exec
import (
"os"
"syscall"
)
func init() {
skipStdinCopyError = func(err error) bool {
// Ignore EPIPE errors copying to stdin if the program
// completed successfully otherwise.
// See Issue 9173.
pe, ok := err.(*os.PathError)
return ok &&
pe.Op == "write" && pe.Path == "|1" &&
pe.Err == syscall.EPIPE
}
}