Fix short write (#28)

* session: pty normalization hack needs to return expected bytes written or chaos ensues, such as short write errors
* _example: renaming to avoid editors that auto-install from making docker binaries in your path that aren't docker
* session: keep extra calculations limited to pty case

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
This commit is contained in:
Jeff Lindsay 2017-02-16 15:59:07 -06:00 committed by GitHub
parent a2a474964c
commit edf30fc0aa
5 changed files with 9 additions and 2 deletions

@ -74,7 +74,7 @@ func dockerRun(cfg *container.Config, sess ssh.Session) (err error, status int64
go func() {
var err error
if cfg.Tty {
_, err = io.Copy(sess, stream.Conn)
_, err = io.Copy(sess, stream.Reader)
} else {
_, err = stdcopy.StdCopy(sess, sess.Stderr(), stream.Reader)
}

@ -65,9 +65,16 @@ type session struct {
func (sess *session) Write(p []byte) (n int, err error) {
if sess.pty != nil {
// normalize \n to \r\n when pty is accepted
m := len(p)
// normalize \n to \r\n when pty is accepted.
// this is a hardcoded shortcut since we don't support terminal modes.
p = bytes.Replace(p, []byte{'\n'}, []byte{'\r', '\n'}, -1)
p = bytes.Replace(p, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'}, -1)
n, err = sess.Channel.Write(p)
if n > m {
n = m
}
return
}
return sess.Channel.Write(p)
}