mirror of https://github.com/containers/podman.git
utils: call MaybeMoveToSubCgroup once
memoize its result and use it for subsequent calls. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
4b547a72ab
commit
16b8d77f9e
|
@ -191,22 +191,32 @@ func MovePauseProcessToScope(pausePidPath string) {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
maybeMoveToSubCgroupSync sync.Once
|
||||
maybeMoveToSubCgroupSyncErr error
|
||||
)
|
||||
|
||||
// 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 {
|
||||
maybeMoveToSubCgroupSync.Do(func() {
|
||||
unifiedMode, err := cgroups.IsCgroup2UnifiedMode()
|
||||
if err != nil {
|
||||
return err
|
||||
maybeMoveToSubCgroupSyncErr = err
|
||||
return
|
||||
}
|
||||
if !unifiedMode {
|
||||
return nil
|
||||
maybeMoveToSubCgroupSyncErr = nil
|
||||
return
|
||||
}
|
||||
cgroup, err := GetOwnCgroup()
|
||||
if err != nil {
|
||||
return err
|
||||
maybeMoveToSubCgroupSyncErr = err
|
||||
return
|
||||
}
|
||||
if cgroup == "/" {
|
||||
return MoveUnderCgroupSubtree("init")
|
||||
maybeMoveToSubCgroupSyncErr = MoveUnderCgroupSubtree("init")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return maybeMoveToSubCgroupSyncErr
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue