diff --git a/integration/exec_test.go b/integration/exec_test.go index cc3740d62..f436133ec 100644 --- a/integration/exec_test.go +++ b/integration/exec_test.go @@ -56,6 +56,49 @@ func testExecPS(t *testing.T, userns bool) { } } +func TestExecEnvironment(t *testing.T) { + if testing.Short() { + return + } + rootfs, err := newRootfs() + if err != nil { + t.Fatal(err) + } + defer remove(rootfs) + + config := newTemplateConfig(rootfs) + container, err := newContainer(config) + if err != nil { + t.Fatal(err) + } + defer container.Destroy() + + buffers := newStdBuffers() + process := &libcontainer.Process{ + Args: []string{"env"}, + Env: []string{ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "TERM=dummy", + "TERM=xterm", + }, + Stdin: buffers.Stdin, + Stdout: buffers.Stdout, + Stderr: buffers.Stderr, + } + + if err := container.Start(process); err != nil { + t.Fatal(err) + } + waitProcess(process, t) + + out := buffers.Stdout.String() + if !strings.Contains(out, "TERM=xterm") || + !strings.Contains(out, "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") || + strings.Contains(out, "TERM=dummy") { + t.Fatalf("unexpected environment, output %q", out) + } +} + func TestIPCPrivate(t *testing.T) { if testing.Short() { return diff --git a/standard_init_linux.go b/standard_init_linux.go index db721b8d7..29619d3cd 100644 --- a/standard_init_linux.go +++ b/standard_init_linux.go @@ -3,6 +3,7 @@ package libcontainer import ( + "os" "syscall" "github.com/docker/libcontainer/apparmor" @@ -89,5 +90,5 @@ func (l *linuxStandardInit) Init() error { if syscall.Getppid() == 1 { return syscall.Kill(syscall.Getpid(), syscall.SIGKILL) } - return system.Execv(l.config.Args[0], l.config.Args[0:], l.config.Env) + return system.Execv(l.config.Args[0], l.config.Args[0:], os.Environ()) }