From ad5eaa8c4cd952df0d4894f11ee0158a9a33a0f3 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 22 Apr 2022 22:00:16 -0400 Subject: os/exec: make skipStdinCopyError a function instead of a variable This makes clearer that skipStdinCopyError is always defined and never overridden in tests. Secondarily, it may also help reduce init-time work and allow the linker and/or inliner to better optimize this package. (Noticed while prototyping #50436.) Change-Id: I4f3c1bc146384a98136a4039f82165ed106c14b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/401897 Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/os/exec/exec.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/os/exec/exec.go') diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index eeca83713b..91c2e003d8 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -230,10 +230,6 @@ func (c *Cmd) argv() []string { return []string{c.Path} } -// skipStdinCopyError optionally specifies a function which reports -// whether the provided stdin copy error should be ignored. -var skipStdinCopyError func(error) bool - func (c *Cmd) stdin() (f *os.File, err error) { if c.Stdin == nil { f, err = os.Open(os.DevNull) @@ -257,7 +253,7 @@ func (c *Cmd) stdin() (f *os.File, err error) { c.closeAfterWait = append(c.closeAfterWait, pw) c.goroutine = append(c.goroutine, func() error { _, err := io.Copy(pw, c.Stdin) - if skip := skipStdinCopyError; skip != nil && skip(err) { + if skipStdinCopyError(err) { err = nil } if err1 := pw.Close(); err == nil { -- cgit v1.3-5-g9baa