From edfe80027144629f1881d02285f478f95fd27b56 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 12 Jul 2022 10:27:42 +0200 Subject: podman: move MaybeMoveToSubCgroup to utils/ Signed-off-by: Giuseppe Scrivano --- utils/utils.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'utils') 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 +} -- cgit v1.2.3-54-g00ecf