diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2022-07-12 10:27:42 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2022-07-13 09:13:06 +0200 |
commit | 4b547a72ab32f86537fec0907c0fbbb98595a688 (patch) | |
tree | 139ffd5665e858c6c69b8abb17a30e0e3f9b734f /utils | |
parent | 255740bdf8a45e644039a83082d6f829c1018512 (diff) | |
download | podman-4b547a72ab32f86537fec0907c0fbbb98595a688.tar.gz podman-4b547a72ab32f86537fec0907c0fbbb98595a688.tar.bz2 podman-4b547a72ab32f86537fec0907c0fbbb98595a688.zip |
podman: move MaybeMoveToSubCgroup to utils/
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utils.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/utils/utils.go b/utils/utils.go index 997de150d..7cf28fda5 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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 +} |