github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/libcontainerd/process_windows.go (about) 1 package libcontainerd 2 3 import ( 4 "io" 5 6 "github.com/Microsoft/hcsshim" 7 ) 8 9 // process keeps the state for both main container process and exec process. 10 type process struct { 11 processCommon 12 13 // Platform specific fields are below here. 14 15 // commandLine is to support returning summary information for docker top 16 commandLine string 17 hcsProcess hcsshim.Process 18 } 19 20 func openReaderFromPipe(p io.ReadCloser) io.Reader { 21 r, w := io.Pipe() 22 go func() { 23 if _, err := io.Copy(w, p); err != nil { 24 r.CloseWithError(err) 25 } 26 w.Close() 27 p.Close() 28 }() 29 return r 30 } 31 32 // fixStdinBackspaceBehavior works around a bug in Windows before build 14350 33 // where it interpreted DEL as VK_DELETE instead of as VK_BACK. This replaces 34 // DEL with BS to work around this. 35 func fixStdinBackspaceBehavior(w io.WriteCloser, osversion string, tty bool) io.WriteCloser { 36 if !tty { 37 return w 38 } 39 if build := buildFromVersion(osversion); build == 0 || build >= 14350 { 40 return w 41 } 42 43 return &delToBsWriter{w} 44 } 45 46 type delToBsWriter struct { 47 io.WriteCloser 48 } 49 50 func (w *delToBsWriter) Write(b []byte) (int, error) { 51 const ( 52 backspace = 0x8 53 del = 0x7f 54 ) 55 bc := make([]byte, len(b)) 56 for i, c := range b { 57 if c == del { 58 bc[i] = backspace 59 } else { 60 bc[i] = c 61 } 62 } 63 return w.WriteCloser.Write(bc) 64 } 65 66 type stdInCloser struct { 67 io.WriteCloser 68 hcsshim.Process 69 } 70 71 func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) *stdInCloser { 72 return &stdInCloser{ 73 WriteCloser: pipe, 74 Process: process, 75 } 76 } 77 78 func (stdin *stdInCloser) Close() error { 79 if err := stdin.WriteCloser.Close(); err != nil { 80 return err 81 } 82 83 return stdin.Process.CloseStdin() 84 } 85 86 func (stdin *stdInCloser) Write(p []byte) (n int, err error) { 87 return stdin.WriteCloser.Write(p) 88 }