Index: src/pkg/os/exec/exec.go |
=================================================================== |
--- a/src/pkg/os/exec/exec.go |
+++ b/src/pkg/os/exec/exec.go |
@@ -87,7 +87,6 @@ |
finished bool // when Wait was called |
childFiles []*os.File |
closeAfterStart []io.Closer |
- closeAfterWait []io.Closer |
goroutine []func() error |
errch chan error // one send per goroutine |
} |
@@ -160,7 +159,6 @@ |
} |
c.closeAfterStart = append(c.closeAfterStart, pr) |
- c.closeAfterWait = append(c.closeAfterWait, pw) |
c.goroutine = append(c.goroutine, func() error { |
_, err := io.Copy(pw, c.Stdin) |
if err1 := pw.Close(); err == nil { |
@@ -202,9 +200,9 @@ |
} |
c.closeAfterStart = append(c.closeAfterStart, pw) |
- c.closeAfterWait = append(c.closeAfterWait, pr) |
c.goroutine = append(c.goroutine, func() error { |
_, err := io.Copy(w, pr) |
+ pr.Close() |
return err |
}) |
return pw, nil |
@@ -235,6 +233,7 @@ |
// Start starts the specified command but does not wait for it to complete. |
func (c *Cmd) Start() error { |
if c.err != nil { |
+ c.closeDescriptors(c.closeAfterStart) |
return c.err |
} |
if c.Process != nil { |
@@ -246,7 +245,6 @@ |
fd, err := setupFd(c) |
if err != nil { |
c.closeDescriptors(c.closeAfterStart) |
- c.closeDescriptors(c.closeAfterWait) |
return err |
} |
c.childFiles = append(c.childFiles, fd) |
@@ -262,7 +260,6 @@ |
}) |
if err != nil { |
c.closeDescriptors(c.closeAfterStart) |
- c.closeDescriptors(c.closeAfterWait) |
return err |
} |
@@ -315,8 +312,6 @@ |
} |
} |
- c.closeDescriptors(c.closeAfterWait) |
- |
if err != nil { |
return err |
} else if !state.Success() { |
@@ -368,13 +363,11 @@ |
} |
c.Stdin = pr |
c.closeAfterStart = append(c.closeAfterStart, pr) |
- c.closeAfterWait = append(c.closeAfterWait, pw) |
return pw, nil |
} |
// StdoutPipe returns a pipe that will be connected to the command's |
// standard output when the command starts. |
-// The pipe will be closed automatically after Wait sees the command exit. |
func (c *Cmd) StdoutPipe() (io.ReadCloser, error) { |
if c.Stdout != nil { |
return nil, errors.New("exec: Stdout already set") |
@@ -388,13 +381,11 @@ |
} |
c.Stdout = pw |
c.closeAfterStart = append(c.closeAfterStart, pw) |
- c.closeAfterWait = append(c.closeAfterWait, pr) |
return pr, nil |
} |
// StderrPipe returns a pipe that will be connected to the command's |
// standard error when the command starts. |
-// The pipe will be closed automatically after Wait sees the command exit. |
func (c *Cmd) StderrPipe() (io.ReadCloser, error) { |
if c.Stderr != nil { |
return nil, errors.New("exec: Stderr already set") |
@@ -408,6 +399,5 @@ |
} |
c.Stderr = pw |
c.closeAfterStart = append(c.closeAfterStart, pw) |
- c.closeAfterWait = append(c.closeAfterWait, pr) |
return pr, nil |
} |