Skip to content

Commit

Permalink
BACKPORT: Fix setup cgroup before prestart hook
Browse files Browse the repository at this point in the history
Upstream reference: opencontainers/runc#1239
Fixes: stefwalter/oci-kvm-hook#3

* User Case:
User could use prestart hook to add block devices to container. so the
hook should have a way to set the permissions of the devices.

Just move cgroup config operation before prestart hook will work.

Signed-off-by: Antonio Murdaca <[email protected]>
  • Loading branch information
runcom committed Jul 17, 2017
1 parent 2ade59f commit 79db05f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ loop:
}
switch procSync.Type {
case procReady:
if err := p.manager.Set(p.config.Config); err != nil {
return newSystemErrorWithCause(err, "setting cgroup config for ready process")
}
// set oom_score_adj
if err := setOomScoreAdj(p.config.Config.OomScoreAdj, p.pid()); err != nil {
return newSystemErrorWithCause(err, "setting oom score for ready process")
Expand All @@ -301,6 +298,10 @@ loop:
}
// call prestart hooks
if !p.config.Config.Namespaces.Contains(configs.NEWNS) {
// Setup cgroup before prestart hook, so that the prestart hook could apply cgroup permissions.
if err := p.manager.Set(p.config.Config); err != nil {
return newSystemErrorWithCause(err, "setting cgroup config for ready process")
}
if p.config.Config.Hooks != nil {
s := configs.HookState{
Version: p.container.config.Version,
Expand All @@ -321,6 +322,10 @@ loop:
}
sentRun = true
case procHooks:
// Setup cgroup before prestart hook, so that the prestart hook could apply cgroup permissions.
if err := p.manager.Set(p.config.Config); err != nil {
return newSystemErrorWithCause(err, "setting cgroup config for procHooks process")
}
if p.config.Config.Hooks != nil {
s := configs.HookState{
Version: p.container.config.Version,
Expand Down

0 comments on commit 79db05f

Please sign in to comment.