summaryrefslogtreecommitdiff
path: root/utils/utils.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2022-07-12 10:27:42 +0200
committerMatthew Heon <matthew.heon@pm.me>2022-07-26 13:08:00 -0400
commitedfe80027144629f1881d02285f478f95fd27b56 (patch)
tree5dd73f3b54bcc9e7498cbc73b9f0f40328367ccb /utils/utils.go
parentb29a52a48a9cbe65f47cbdbb618366421ee851b5 (diff)
downloadpodman-edfe80027144629f1881d02285f478f95fd27b56.tar.gz
podman-edfe80027144629f1881d02285f478f95fd27b56.tar.bz2
podman-edfe80027144629f1881d02285f478f95fd27b56.zip
podman: move MaybeMoveToSubCgroup to utils/
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'utils/utils.go')
-rw-r--r--utils/utils.go20
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
+}