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

Commit 0195469

Browse files
committed
execin should honour rlimit of the container
Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <[email protected]> (github: dqminh)
1 parent 2f1b2ce commit 0195469

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

integration/execin_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,74 @@ func TestExecIn(t *testing.T) {
8181
t.Fatalf("unexpected running process, output %q", out)
8282
}
8383
}
84+
85+
func TestExecInRlimit(t *testing.T) {
86+
if testing.Short() {
87+
return
88+
}
89+
90+
rootfs, err := newRootFs()
91+
if err != nil {
92+
t.Fatal(err)
93+
}
94+
defer remove(rootfs)
95+
96+
config := newTemplateConfig(rootfs)
97+
if err := writeConfig(config); err != nil {
98+
t.Fatalf("failed to write config %s", err)
99+
}
100+
101+
// start the container
102+
containerErr := make(chan error, 1)
103+
containerCmd := &exec.Cmd{}
104+
var statePath string
105+
createCmd := func(container *libcontainer.Config, console, dataPath, init string,
106+
pipe *os.File, args []string) *exec.Cmd {
107+
containerCmd = namespaces.DefaultCreateCommand(container, console, dataPath, init, pipe, args)
108+
statePath = dataPath
109+
return containerCmd
110+
}
111+
var containerStart sync.WaitGroup
112+
containerStart.Add(1)
113+
go func() {
114+
buffers := newStdBuffers()
115+
_, err := namespaces.Exec(config,
116+
buffers.Stdin, buffers.Stdout, buffers.Stderr,
117+
"", config.RootFs, []string{"sleep", "10"},
118+
createCmd, containerStart.Done)
119+
containerErr <- err
120+
}()
121+
containerStart.Wait()
122+
123+
defer func() {
124+
// kill the container
125+
if containerCmd.Process != nil {
126+
containerCmd.Process.Kill()
127+
}
128+
if err := <-containerErr; err != nil {
129+
t.Fatal(err)
130+
}
131+
}()
132+
133+
// start the exec process
134+
state, err := libcontainer.GetState(statePath)
135+
if err != nil {
136+
t.Fatalf("failed to get state %s", err)
137+
}
138+
buffers := newStdBuffers()
139+
execErr := make(chan error, 1)
140+
go func() {
141+
_, err := namespaces.ExecIn(config, state, []string{"/bin/sh", "-c", "ulimit -n"},
142+
os.Args[0], "exec", buffers.Stdin, buffers.Stdout, buffers.Stderr,
143+
"", nil)
144+
execErr <- err
145+
}()
146+
if err := <-execErr; err != nil {
147+
t.Fatalf("exec finished with error %s", err)
148+
}
149+
150+
out := buffers.Stdout.String()
151+
if limit := strings.TrimSpace(out); limit != "1024" {
152+
t.Fatalf("expected rlimit to be 1024, got %s", limit)
153+
}
154+
}

namespaces/execin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func FinalizeSetns(container *libcontainer.Config, args []string) error {
9797
return err
9898
}
9999

100+
if err := setupRlimits(container); err != nil {
101+
return fmt.Errorf("setup rlimits %s", err)
102+
}
103+
100104
if err := FinalizeNamespace(container); err != nil {
101105
return err
102106
}

0 commit comments

Comments
 (0)