Don't fail on setting -ve oom score when rootless

This allows non-privileged users to use containerd.
If a non root user tried to set a negative oom score adjustment,
it will fail. Containerd should not fail if running rootless.

This is part of a larger track of work integrating containerd
into Cloudfoundry's garden with support for rootless.

[#156343443]

Signed-off-by: Danail Branekov <danailster@gmail.com>
This commit is contained in:
Claudia Beresford
2018-05-04 17:06:01 +01:00
committed by Danail Branekov
parent 40c3acd36c
commit 544b985ff2
3 changed files with 156 additions and 1 deletions

View File

@@ -38,7 +38,7 @@ func SetOOMScore(pid, score int) error {
}
defer f.Close()
if _, err = f.WriteString(strconv.Itoa(score)); err != nil {
if os.IsPermission(err) && system.RunningInUserNS() {
if os.IsPermission(err) && (system.RunningInUserNS() || RunningUnprivileged()) {
return nil
}
return err