diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-11-25 11:59:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 11:59:09 +0100 |
commit | 12f73d5f88d8646058bbb4e673b04b413732dbe2 (patch) | |
tree | 479aaf581154a1b9b8fffa8f45473aa11e45929d /libpod/container.go | |
parent | 93138541f3119b81c170e5ce904a8c4e6cece842 (diff) | |
parent | e648122b2986ea3bdcee33ebaef8731e574e8f54 (diff) | |
download | podman-12f73d5f88d8646058bbb4e673b04b413732dbe2.tar.gz podman-12f73d5f88d8646058bbb4e673b04b413732dbe2.tar.bz2 podman-12f73d5f88d8646058bbb4e673b04b413732dbe2.zip |
Merge pull request #12403 from giuseppe/improve-cgroup-detection
libpod: improve heuristic to detect cgroup
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go index c38acb513..482af43f3 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -6,9 +6,11 @@ import ( "io/ioutil" "net" "os" + "strings" "time" types040 "github.com/containernetworking/cni/pkg/types/040" + "github.com/containers/common/pkg/config" "github.com/containers/common/pkg/secrets" "github.com/containers/image/v5/manifest" "github.com/containers/podman/v3/libpod/define" @@ -963,6 +965,29 @@ func (c *Container) cGroupPath() (string, error) { return "", errors.Errorf("could not find any cgroup in %q", procPath) } + cgroupManager := c.CgroupManager() + switch { + case c.config.CgroupsMode == cgroupSplit: + name := fmt.Sprintf("/libpod-payload-%s/", c.ID()) + if index := strings.LastIndex(cgroupPath, name); index >= 0 { + return cgroupPath[:index+len(name)-1], nil + } + case cgroupManager == config.CgroupfsCgroupsManager: + name := fmt.Sprintf("/libpod-%s/", c.ID()) + if index := strings.LastIndex(cgroupPath, name); index >= 0 { + return cgroupPath[:index+len(name)-1], nil + } + case cgroupManager == config.SystemdCgroupsManager: + // When running under systemd, try to detect the scope that was requested + // to be created. It improves the heuristic since we report the first + // cgroup that was created instead of the cgroup where PID 1 might have + // moved to. + name := fmt.Sprintf("/libpod-%s.scope/", c.ID()) + if index := strings.LastIndex(cgroupPath, name); index >= 0 { + return cgroupPath[:index+len(name)-1], nil + } + } + return cgroupPath, nil } |