Browse code

Add ulimit support to libcontainerd addprocess

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/03/24 11:54:32
Showing 3 changed files
... ...
@@ -485,6 +485,17 @@ func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) {
485 485
 	dockerCmd(c, "exec", "parent", "true")
486 486
 }
487 487
 
488
+func (s *DockerSuite) TestExecUlimits(c *check.C) {
489
+	testRequires(c, DaemonIsLinux)
490
+	name := "testexeculimits"
491
+	runSleepingContainer(c, "-d", "--ulimit", "nproc=21", "--name", name)
492
+	c.Assert(waitRun(name), checker.IsNil)
493
+
494
+	out, _, err := dockerCmdWithError("exec", name, "sh", "-c", "ulimit -p")
495
+	c.Assert(err, checker.IsNil)
496
+	c.Assert(strings.TrimSpace(out), checker.Equals, "21")
497
+}
498
+
488 499
 // #15750
489 500
 func (s *DockerSuite) TestExecStartFails(c *check.C) {
490 501
 	// TODO Windows CI. This test should be portable. Figure out why it fails
... ...
@@ -79,6 +79,7 @@ func (clnt *client) AddProcess(containerID, processFriendlyName string, specp Pr
79 79
 		ApparmorProfile: sp.ApparmorProfile,
80 80
 		SelinuxLabel:    sp.SelinuxLabel,
81 81
 		NoNewPrivileges: sp.NoNewPrivileges,
82
+		Rlimits:         convertRlimits(sp.Rlimits),
82 83
 	}
83 84
 
84 85
 	iopipe, err := p.openFifos(sp.Terminal)
... ...
@@ -39,3 +39,14 @@ func systemPid(ctr *containerd.Container) uint32 {
39 39
 	}
40 40
 	return pid
41 41
 }
42
+
43
+func convertRlimits(sr []specs.Rlimit) (cr []*containerd.Rlimit) {
44
+	for _, r := range sr {
45
+		cr = append(cr, &containerd.Rlimit{
46
+			Type: r.Type,
47
+			Hard: r.Hard,
48
+			Soft: r.Soft,
49
+		})
50
+	}
51
+	return
52
+}