Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
properly setup init process environment
Browse files Browse the repository at this point in the history
instead of taking the raw config.Env, we use `os.Environ()` which works
correctly because the environment has been setup properly with
`newContainerInit`

Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
  • Loading branch information
dqminh committed Feb 27, 2015
1 parent 1261a09 commit b392a23
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion standard_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package libcontainer

import (
"os"
"syscall"

"github.com/docker/libcontainer/apparmor"
Expand Down Expand Up @@ -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())
}

0 comments on commit b392a23

Please sign in to comment.