]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: pass an unmodified environment to a go run program
authorIan Lance Taylor <iant@golang.org>
Tue, 21 Jul 2015 19:17:29 +0000 (12:17 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 21 Jul 2015 22:19:00 +0000 (22:19 +0000)
Fixes #11709.
Fixed #11449.

Change-Id: If8fdb27d3dc25fb7017226d143a29cbebc1374c5
Reviewed-on: https://go-review.googlesource.com/12483
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/generate.go
src/cmd/go/go_test.go
src/cmd/go/main.go
src/cmd/go/run.go

index 98513ce122b5c3e789f5c328dedac5fdf37f0e40..efdc229b2281a2e0463e12d4308c85299ed56c74 100644 (file)
@@ -402,7 +402,7 @@ func (g *Generator) exec(words []string) {
                "GOFILE=" + g.file,
                "GOPACKAGE=" + g.pkg,
        }
-       cmd.Env = mergeEnvLists(env, os.Environ())
+       cmd.Env = mergeEnvLists(env, origEnv)
        err := cmd.Run()
        if err != nil {
                g.errorf("running %q: %s", words[0], err)
index a6353f580f6a06c3d163cef7c20bbf4dc85802b7..147917c46fd2ded2804fc151080fc808833e1c1a 100644 (file)
@@ -2229,3 +2229,18 @@ func TestGoInstallShadowedGOPATH(t *testing.T) {
        tg.runFail("install")
        tg.grepStderr("no install location for.*gopath2.src.test: hidden by .*gopath1.src.test", "missing error")
 }
+
+func TestIssue11709(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.tempFile("run.go", `
+               package main
+               import "os"
+               func main() {
+                       if os.Getenv("TERM") != "" {
+                               os.Exit(1)
+                       }
+               }`)
+       tg.unsetenv("TERM")
+       tg.run("run", tg.path("run.go"))
+}
index c8267e919e47878b0789b3654e14904cd547829f..ae1f954b3e87e23dfc2a1ec8a10955627a67f5e9 100644 (file)
@@ -112,6 +112,8 @@ func setExitStatus(n int) {
        exitMu.Unlock()
 }
 
+var origEnv []string
+
 func main() {
        _ = go11tag
        flag.Usage = usage
@@ -159,6 +161,7 @@ func main() {
        // the same default computation of these as we do,
        // but in practice there might be skew
        // This makes sure we all agree.
+       origEnv = os.Environ()
        for _, env := range mkEnv() {
                if os.Getenv(env.name) != env.value {
                        os.Setenv(env.name, env.value)
index f815cb982b2c993ab7030515cc97824e489f9dbd..6a04a9e19da9451a697e52b5e1451826cb2d38bd 100644 (file)
@@ -137,6 +137,7 @@ func runStdin(cmdline []string) {
        cmd.Stdin = os.Stdin
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
+       cmd.Env = origEnv
        startSigHandlers()
        if err := cmd.Run(); err != nil {
                errorf("%v", err)