libcontainer: handle unset oomScoreAdj corectly

Previously if oomScoreAdj was not set in config.json we would implicitly
set oom_score_adj to 0. This is not allowed according to the spec:

> If oomScoreAdj is not set, the runtime MUST NOT change the value of
> oom_score_adj.

Change this so that we do not modify oom_score_adj if oomScoreAdj is not
present in the configuration. While this modifies our internal
configuration types, the on-disk format is still compatible.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai
2018-03-16 11:54:47 +11:00
parent 03e585985f
commit fd3a6e6c83
6 changed files with 22 additions and 15 deletions
+3 -3
View File
@@ -1075,7 +1075,7 @@ func TestOomScoreAdj(t *testing.T) {
defer remove(rootfs)
config := newTemplateConfig(rootfs)
config.OomScoreAdj = 200
config.OomScoreAdj = ptrInt(200)
factory, err := libcontainer.New(root, libcontainer.Cgroupfs)
ok(t, err)
@@ -1100,8 +1100,8 @@ func TestOomScoreAdj(t *testing.T) {
outputOomScoreAdj := strings.TrimSpace(string(stdout.Bytes()))
// Check that the oom_score_adj matches the value that was set as part of config.
if outputOomScoreAdj != strconv.Itoa(config.OomScoreAdj) {
t.Fatalf("Expected oom_score_adj %d; got %q", config.OomScoreAdj, outputOomScoreAdj)
if outputOomScoreAdj != strconv.Itoa(*config.OomScoreAdj) {
t.Fatalf("Expected oom_score_adj %d; got %q", *config.OomScoreAdj, outputOomScoreAdj)
}
}