diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2021-09-16 12:44:45 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2021-09-17 10:38:00 +0200 |
commit | e6fe5d6312e1569b688baeb1aa1cee3030921076 (patch) | |
tree | a9f22978d31d48f8a7f1695521c9e68bae3f9e82 /utils/utils.go | |
parent | ae5a5b51b068f62c8ec71bb9ec555d2c5c5f4f37 (diff) | |
download | podman-e6fe5d6312e1569b688baeb1aa1cee3030921076.tar.gz podman-e6fe5d6312e1569b688baeb1aa1cee3030921076.tar.bz2 podman-e6fe5d6312e1569b688baeb1aa1cee3030921076.zip |
system: move MovePauseProcessToScope to utils
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
(cherry picked from commit 72534a74b3c2ff35ae1711a890406a6bce5fa44f)
Diffstat (limited to 'utils/utils.go')
-rw-r--r-- | utils/utils.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/utils/utils.go b/utils/utils.go index e2760d225..185ac4865 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -172,3 +172,28 @@ func RunsOnSystemd() bool { }) return runsOnSystemd } + +func moveProcessToScope(pidPath, slice, scope string) error { + data, err := ioutil.ReadFile(pidPath) + if err != nil { + return errors.Wrapf(err, "cannot read pid file %s", pidPath) + } + pid, err := strconv.ParseUint(string(data), 10, 0) + if err != nil { + return errors.Wrapf(err, "cannot parse pid file %s", pidPath) + } + return RunUnderSystemdScope(int(pid), slice, scope) +} + +// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to +// a separate scope. +func MovePauseProcessToScope(pausePidPath string) { + err := moveProcessToScope(pausePidPath, "user.slice", "podman-pause.scope") + if err != nil { + if RunsOnSystemd() { + logrus.Warnf("Failed to add pause process to systemd sandbox cgroup: %v", err) + } else { + logrus.Debugf("Failed to add pause process to systemd sandbox cgroup: %v", err) + } + } +} |