Browse code

Windows: Use image version, not OS version for TTY fixup

A previous change added a TTY fixup for stdin on older Windows versions to
work around a Windows issue with backspace/delete behavior. This change
used the OS version to determine whether to activate the behavior.
However, the Windows bug is actually in the image, not the OS, so it
should have used the image's OS version.

This ensures that a Server TP5 container running on Windows 10 will have
reasonable console behavior.

Signed-off-by: John Starks <jostarks@microsoft.com>

John Starks authored on 2016/05/26 04:15:34
Showing 5 changed files
... ...
@@ -34,6 +34,8 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
34 34
 		return nil, fmt.Errorf("Failed to graph.Get on ImageID %s - %s", c.ImageID, err)
35 35
 	}
36 36
 
37
+	s.Platform.OSVersion = img.OSVersion
38
+
37 39
 	// In base spec
38 40
 	s.Hostname = c.FullHostname()
39 41
 
... ...
@@ -222,7 +222,7 @@ func (clnt *client) AddProcess(containerID, processFriendlyName string, procToAd
222 222
 	iopipe.Stdin = createStdInCloser(stdin, newProcess)
223 223
 
224 224
 	// TEMP: Work around Windows BS/DEL behavior.
225
-	iopipe.Stdin = fixStdinBackspaceBehavior(iopipe.Stdin, procToAdd.Terminal)
225
+	iopipe.Stdin = fixStdinBackspaceBehavior(iopipe.Stdin, container.ociSpec.Platform.OSVersion, procToAdd.Terminal)
226 226
 
227 227
 	// Convert io.ReadClosers to io.Readers
228 228
 	if stdout != nil {
... ...
@@ -106,7 +106,7 @@ func (ctr *container) start() error {
106 106
 	iopipe.Stdin = createStdInCloser(stdin, hcsProcess)
107 107
 
108 108
 	// TEMP: Work around Windows BS/DEL behavior.
109
-	iopipe.Stdin = fixStdinBackspaceBehavior(iopipe.Stdin, ctr.ociSpec.Process.Terminal)
109
+	iopipe.Stdin = fixStdinBackspaceBehavior(iopipe.Stdin, ctr.ociSpec.Platform.OSVersion, ctr.ociSpec.Process.Terminal)
110 110
 
111 111
 	// Convert io.ReadClosers to io.Readers
112 112
 	if stdout != nil {
... ...
@@ -2,9 +2,10 @@ package libcontainerd
2 2
 
3 3
 import (
4 4
 	"io"
5
+	"strconv"
6
+	"strings"
5 7
 
6 8
 	"github.com/Microsoft/hcsshim"
7
-	"github.com/docker/docker/pkg/system"
8 9
 )
9 10
 
10 11
 // process keeps the state for both main container process and exec process.
... ...
@@ -33,10 +34,19 @@ func openReaderFromPipe(p io.ReadCloser) io.Reader {
33 33
 // fixStdinBackspaceBehavior works around a bug in Windows before build 14350
34 34
 // where it interpreted DEL as VK_DELETE instead of as VK_BACK. This replaces
35 35
 // DEL with BS to work around this.
36
-func fixStdinBackspaceBehavior(w io.WriteCloser, tty bool) io.WriteCloser {
37
-	if !tty || system.GetOSVersion().Build >= 14350 {
36
+func fixStdinBackspaceBehavior(w io.WriteCloser, osversion string, tty bool) io.WriteCloser {
37
+	if !tty {
38 38
 		return w
39 39
 	}
40
+	v := strings.Split(osversion, ".")
41
+	if len(v) < 3 {
42
+		return w
43
+	}
44
+
45
+	if build, err := strconv.Atoi(v[2]); err != nil || build >= 14350 {
46
+		return w
47
+	}
48
+
40 49
 	return &delToBsWriter{w}
41 50
 }
42 51
 
... ...
@@ -86,6 +86,8 @@ type Platform struct {
86 86
 	OS string `json:"os"`
87 87
 	// Arch is the architecture
88 88
 	Arch string `json:"arch"`
89
+	// OSVersion is the version of the operating system.
90
+	OSVersion string `json:"os.version,omitempty"`
89 91
 }
90 92
 
91 93
 // Mount specifies a mount for a container.