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