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

Commit

Permalink
setup setns process environment with os.Environ()
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 Mar 1, 2015
1 parent 526a39e commit 71fc3fa
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
68 changes: 68 additions & 0 deletions integration/execin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,74 @@ func TestExecIn(t *testing.T) {
}
}

func TestExecInEnvironment(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()

// Execute a first process in the container
stdinR, stdinW, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
process := &libcontainer.Process{
Args: []string{"cat"},
Env: standardEnvironment,
Stdin: stdinR,
}
err = container.Start(process)
stdinR.Close()
defer stdinW.Close()
if err != nil {
t.Fatal(err)
}

buffers := newStdBuffers()
ps := &libcontainer.Process{
Args: []string{"env"},
Env: []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"DEBUG=true",
"DEBUG=false",
"ENV=test",
},
Stdin: buffers.Stdin,
Stdout: buffers.Stdout,
Stderr: buffers.Stderr,
}
err = container.Start(ps)
if err != nil {
t.Fatal(err)
}
if _, err := ps.Wait(); err != nil {
out := buffers.Stdout.String()
t.Fatal(err, out)
}
stdinW.Close()
if _, err := process.Wait(); err != nil {
t.Log(err)
}
out := buffers.Stdout.String()
// check execin's process environment
if !strings.Contains(out, "DEBUG=false") ||
!strings.Contains(out, "ENV=test") ||
!strings.Contains(out, "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") ||
strings.Contains(out, "DEBUG=true") {
t.Fatalf("unexpected running process, output %q", out)
}
}

func TestExecInRlimit(t *testing.T) {
if testing.Short() {
return
Expand Down
4 changes: 3 additions & 1 deletion setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package libcontainer

import (
"os"

"github.com/docker/libcontainer/apparmor"
"github.com/docker/libcontainer/label"
"github.com/docker/libcontainer/system"
Expand All @@ -29,5 +31,5 @@ func (l *linuxSetnsInit) Init() error {
return err
}
}
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 71fc3fa

Please sign in to comment.