podman: move MaybeMoveToSubCgroup to utils/

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2022-07-12 10:27:42 +02:00
committed by Matthew Heon
parent b29a52a48a
commit edfe800271
2 changed files with 21 additions and 22 deletions

View File

@ -190,3 +190,23 @@ func MovePauseProcessToScope(pausePidPath string) {
}
}
}
// MaybeMoveToSubCgroup moves the current process in a sub cgroup when
// it is running in the root cgroup on a system that uses cgroupv2.
func MaybeMoveToSubCgroup() error {
unifiedMode, err := cgroups.IsCgroup2UnifiedMode()
if err != nil {
return err
}
if !unifiedMode {
return nil
}
cgroup, err := GetOwnCgroup()
if err != nil {
return err
}
if cgroup == "/" {
return MoveUnderCgroupSubtree("init")
}
return nil
}