From 72534a74b3c2ff35ae1711a890406a6bce5fa44f Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 16 Sep 2021 12:44:45 +0200 Subject: system: move MovePauseProcessToScope to utils Signed-off-by: Giuseppe Scrivano --- utils/utils.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'utils') 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) + } + } +} -- cgit v1.2.3-54-g00ecf