From b906df653b58bc2ab9b93e18f62adccc8c1419b7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Nov 2016 17:55:28 -0800 Subject: os/exec: add closeOnce.WriteString method Add an explicit WriteString method to closeOnce that acquires the writers lock. This overrides the one promoted from the embedded *os.File field. The promoted one naturally does not acquire the lock, and can therefore race with the Close method. Fixes #17647. Change-Id: I3460f2a0d503449481cfb2fd4628b4855ab0ecdf Reviewed-on: https://go-review.googlesource.com/33298 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/exec/exec.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/os/exec/exec.go') diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index a3a0f20ebc..c4c5168b98 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -579,6 +579,13 @@ func (c *closeOnce) Write(b []byte) (int, error) { return n, err } +func (c *closeOnce) WriteString(s string) (int, error) { + c.writers.RLock() + n, err := c.File.WriteString(s) + c.writers.RUnlock() + return n, err +} + // StdoutPipe returns a pipe that will be connected to the command's // standard output when the command starts. // -- cgit v1.3