// are inherited by the child process.
childIOFiles []io.Closer
- // goroutinePipes holds closers for the parent's end of any pipes
+ // parentIOPipes holds closers for the parent's end of any pipes
// connected to the child's stdin, stdout, and/or stderr streams
- // that are pumped (and ultimately closed) by goroutines controlled by
- // the Cmd itself (not supplied by or returned to the caller).
- goroutinePipes []io.Closer
-
- // userPipes holds closers for the parent's end of any pipes
- // connected to the child's stdin, stdout and/or stderr streams
- // that were opened and returned by the Cmd's Pipe methods.
- // These should be closed when Wait completes.
- userPipes []io.Closer
+ // that were opened by the Cmd itself (not supplied by the caller).
+ // These should be closed after Wait sees the command exit.
+ parentIOPipes []io.Closer
// goroutine holds a set of closures to execute to copy data
// to and/or from the command's I/O pipes.
}
c.childIOFiles = append(c.childIOFiles, pr)
- c.goroutinePipes = append(c.goroutinePipes, pw)
+ c.parentIOPipes = append(c.parentIOPipes, pw)
c.goroutine = append(c.goroutine, func() error {
_, err := io.Copy(pw, c.Stdin)
if skipStdinCopyError(err) {
}
c.childIOFiles = append(c.childIOFiles, pw)
- c.goroutinePipes = append(c.goroutinePipes, pr)
+ c.parentIOPipes = append(c.parentIOPipes, pr)
c.goroutine = append(c.goroutine, func() error {
_, err := io.Copy(w, pr)
pr.Close() // in case io.Copy stopped due to write error
return pw, nil
}
-func (c *Cmd) closeDescriptors(closers []io.Closer) {
+func closeDescriptors(closers []io.Closer) {
for _, fd := range closers {
fd.Close()
}
started := false
defer func() {
- c.closeDescriptors(c.childIOFiles)
+ closeDescriptors(c.childIOFiles)
c.childIOFiles = nil
if !started {
- c.closeDescriptors(c.goroutinePipes)
- c.goroutinePipes = nil
- c.closeDescriptors(c.userPipes)
- c.userPipes = nil
+ closeDescriptors(c.parentIOPipes)
+ c.parentIOPipes = nil
}
}()
err = copyErr
}
}
- c.goroutinePipes = nil // Already closed by their respective goroutines.
-
- c.closeDescriptors(c.userPipes)
- c.userPipes = nil
+ closeDescriptors(c.parentIOPipes)
+ c.parentIOPipes = nil
return err
}
c.Stdin = pr
c.childIOFiles = append(c.childIOFiles, pr)
wc := &closeOnce{File: pw}
- c.userPipes = append(c.userPipes, wc)
+ c.parentIOPipes = append(c.parentIOPipes, wc)
return wc, nil
}
}
c.Stdout = pw
c.childIOFiles = append(c.childIOFiles, pw)
- c.userPipes = append(c.userPipes, pr)
+ c.parentIOPipes = append(c.parentIOPipes, pr)
return pr, nil
}
}
c.Stderr = pw
c.childIOFiles = append(c.childIOFiles, pw)
- c.userPipes = append(c.userPipes, pr)
+ c.parentIOPipes = append(c.parentIOPipes, pr)
return pr, nil
}