diff options
author | Antonio Murdaca <me@runcom.ninja> | 2015-03-29 23:17:23 +0200 |
---|---|---|
committer | Antonio Murdaca <me@runcom.ninja> | 2015-04-14 01:37:36 +0200 |
commit | c30a55f14dbbe3971ba0ac716ba69a60868f4490 (patch) | |
tree | 2e3d8742b53fa529e7e3af004f56824c91e967fb /daemon/attach.go | |
parent | 7ecf4e5d4dfbb0c9adcdea65f51d40fd6d4a1f43 (diff) | |
download | docker-c30a55f14dbbe3971ba0ac716ba69a60868f4490.tar.gz |
Refactor utils/utils, fixes #11923
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
Diffstat (limited to 'daemon/attach.go')
-rw-r--r-- | daemon/attach.go | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/daemon/attach.go b/daemon/attach.go index f95de41d52..b2b8d09067 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -10,7 +10,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/promise" - "github.com/docker/docker/utils" ) func (c *Container) AttachWithLogs(stdin io.ReadCloser, stdout, stderr io.Writer, logs, stream bool) error { @@ -131,7 +130,7 @@ func attach(streamConfig *StreamConfig, openStdin, stdinOnce, tty bool, stdin io var err error if tty { - _, err = utils.CopyEscapable(cStdin, stdin) + _, err = copyEscapable(cStdin, stdin) } else { _, err = io.Copy(cStdin, stdin) @@ -185,3 +184,46 @@ func attach(streamConfig *StreamConfig, openStdin, stdinOnce, tty bool, stdin io return nil }) } + +// Code c/c from io.Copy() modified to handle escape sequence +func copyEscapable(dst io.Writer, src io.ReadCloser) (written int64, err error) { + buf := make([]byte, 32*1024) + for { + nr, er := src.Read(buf) + if nr > 0 { + // ---- Docker addition + // char 16 is C-p + if nr == 1 && buf[0] == 16 { + nr, er = src.Read(buf) + // char 17 is C-q + if nr == 1 && buf[0] == 17 { + if err := src.Close(); err != nil { + return 0, err + } + return 0, nil + } + } + // ---- End of docker + nw, ew := dst.Write(buf[0:nr]) + if nw > 0 { + written += int64(nw) + } + if ew != nil { + err = ew + break + } + if nr != nw { + err = io.ErrShortWrite + break + } + } + if er == io.EOF { + break + } + if er != nil { + err = er + break + } + } + return written, err +} |