Browse code

Windows: Don't set PATH/TERM on exec

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/09/29 05:34:47
Showing 2 changed files
... ...
@@ -3,6 +3,7 @@ package daemon
3 3
 import (
4 4
 	"fmt"
5 5
 	"io"
6
+	"runtime"
6 7
 	"strings"
7 8
 	"time"
8 9
 
... ...
@@ -123,11 +124,15 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
123 123
 	execConfig.Tty = config.Tty
124 124
 	execConfig.Privileged = config.Privileged
125 125
 	execConfig.User = config.User
126
-	execConfig.Env = []string{
127
-		"PATH=" + system.DefaultPathEnv,
128
-	}
129
-	if config.Tty {
130
-		execConfig.Env = append(execConfig.Env, "TERM=xterm")
126
+
127
+	// On Windows, don't default the path, let the platform do it. Also TERM isn't meaningful
128
+	if runtime.GOOS != "windows" {
129
+		execConfig.Env = []string{
130
+			"PATH=" + system.DefaultPathEnv,
131
+		}
132
+		if config.Tty {
133
+			execConfig.Env = append(execConfig.Env, "TERM=xterm")
134
+		}
131 135
 	}
132 136
 	execConfig.Env = utils.ReplaceOrAppendEnvValues(execConfig.Env, container.Config.Env)
133 137
 	if len(execConfig.User) == 0 {
... ...
@@ -509,3 +509,14 @@ func (s *DockerSuite) TestExecStartFails(c *check.C) {
509 509
 	c.Assert(err, checker.NotNil, check.Commentf(out))
510 510
 	c.Assert(out, checker.Contains, "executable file not found")
511 511
 }
512
+
513
+// Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297
514
+func (s *DockerSuite) TestExecWindowsPathNotWiped(c *check.C) {
515
+	testRequires(c, DaemonIsWindows)
516
+	out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60")
517
+	c.Assert(waitRun(strings.TrimSpace(out)), check.IsNil)
518
+
519
+	out, _ = dockerCmd(c, "exec", "testing", "powershell", "write-host", "$env:PATH")
520
+	out = strings.ToLower(strings.Trim(out, "\r\n"))
521
+	c.Assert(out, checker.Contains, `windowspowershell\v1.0`)
522
+}