diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-13 05:11:45 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-13 05:11:45 +0000 |
commit | df4aa89a5e7acb315655f193e7f549e8d32367e2 (patch) | |
tree | eb5eccc07097c5fcf940967f33ab84a7d47c96fe /libgo/go/exp/ssh/session.go | |
parent | f83fa0bf8f411697ec908cfa86ee6faf4cd9c476 (diff) | |
download | gcc-df4aa89a5e7acb315655f193e7f549e8d32367e2.zip gcc-df4aa89a5e7acb315655f193e7f549e8d32367e2.tar.gz gcc-df4aa89a5e7acb315655f193e7f549e8d32367e2.tar.bz2 |
libgo: Update to weekly.2011-12-22.
From-SVN: r183150
Diffstat (limited to 'libgo/go/exp/ssh/session.go')
-rw-r--r-- | libgo/go/exp/ssh/session.go | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/libgo/go/exp/ssh/session.go b/libgo/go/exp/ssh/session.go index bf9a88e..807dd87 100644 --- a/libgo/go/exp/ssh/session.go +++ b/libgo/go/exp/ssh/session.go @@ -68,10 +68,12 @@ type Session struct { *clientChan // the channel backing this session - started bool // true once Start, Run or Shell is invoked. - closeAfterWait []io.Closer - copyFuncs []func() error - errch chan error // one send per copyFunc + started bool // true once Start, Run or Shell is invoked. + copyFuncs []func() error + errch chan error // one send per copyFunc + + // true if pipe method is active + stdinpipe, stdoutpipe, stderrpipe bool } // RFC 4254 Section 6.4. @@ -237,11 +239,9 @@ func (s *Session) waitForResponse() error { func (s *Session) start() error { s.started = true - type F func(*Session) error + type F func(*Session) for _, setupFd := range []F{(*Session).stdin, (*Session).stdout, (*Session).stderr} { - if err := setupFd(s); err != nil { - return err - } + setupFd(s) } s.errch = make(chan error, len(s.copyFuncs)) @@ -274,9 +274,6 @@ func (s *Session) Wait() error { copyError = err } } - for _, fd := range s.closeAfterWait { - fd.Close() - } if waitErr != nil { return waitErr } @@ -341,7 +338,10 @@ func (s *Session) wait() error { return &ExitError{wm} } -func (s *Session) stdin() error { +func (s *Session) stdin() { + if s.stdinpipe { + return + } if s.Stdin == nil { s.Stdin = new(bytes.Buffer) } @@ -352,10 +352,12 @@ func (s *Session) stdin() error { } return err }) - return nil } -func (s *Session) stdout() error { +func (s *Session) stdout() { + if s.stdoutpipe { + return + } if s.Stdout == nil { s.Stdout = ioutil.Discard } @@ -363,10 +365,12 @@ func (s *Session) stdout() error { _, err := io.Copy(s.Stdout, s.clientChan.stdout) return err }) - return nil } -func (s *Session) stderr() error { +func (s *Session) stderr() { + if s.stderrpipe { + return + } if s.Stderr == nil { s.Stderr = ioutil.Discard } @@ -374,7 +378,6 @@ func (s *Session) stderr() error { _, err := io.Copy(s.Stderr, s.clientChan.stderr) return err }) - return nil } // StdinPipe returns a pipe that will be connected to the @@ -386,10 +389,8 @@ func (s *Session) StdinPipe() (io.WriteCloser, error) { if s.started { return nil, errors.New("ssh: StdinPipe after process started") } - pr, pw := io.Pipe() - s.Stdin = pr - s.closeAfterWait = append(s.closeAfterWait, pr) - return pw, nil + s.stdinpipe = true + return s.clientChan.stdin, nil } // StdoutPipe returns a pipe that will be connected to the @@ -398,17 +399,15 @@ func (s *Session) StdinPipe() (io.WriteCloser, error) { // stdout and stderr streams. If the StdoutPipe reader is // not serviced fast enought it may eventually cause the // remote command to block. -func (s *Session) StdoutPipe() (io.ReadCloser, error) { +func (s *Session) StdoutPipe() (io.Reader, error) { if s.Stdout != nil { return nil, errors.New("ssh: Stdout already set") } if s.started { return nil, errors.New("ssh: StdoutPipe after process started") } - pr, pw := io.Pipe() - s.Stdout = pw - s.closeAfterWait = append(s.closeAfterWait, pw) - return pr, nil + s.stdoutpipe = true + return s.clientChan.stdout, nil } // StderrPipe returns a pipe that will be connected to the @@ -417,17 +416,15 @@ func (s *Session) StdoutPipe() (io.ReadCloser, error) { // stdout and stderr streams. If the StderrPipe reader is // not serviced fast enought it may eventually cause the // remote command to block. -func (s *Session) StderrPipe() (io.ReadCloser, error) { +func (s *Session) StderrPipe() (io.Reader, error) { if s.Stderr != nil { return nil, errors.New("ssh: Stderr already set") } if s.started { return nil, errors.New("ssh: StderrPipe after process started") } - pr, pw := io.Pipe() - s.Stderr = pw - s.closeAfterWait = append(s.closeAfterWait, pw) - return pr, nil + s.stderrpipe = true + return s.clientChan.stderr, nil } // TODO(dfc) add Output and CombinedOutput helpers |