abi: fix detection for systemd

create a scope everytime we don't own the current cgroup and we are
running on systemd.

Closes: https://github.com/containers/podman/issues/6734

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2020-08-17 15:58:16 +02:00
parent 748e8829da
commit b3f5c93ecc

@ -70,8 +70,13 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command)
if err != nil {
return err
}
initCommand, err := ioutil.ReadFile("/proc/1/comm")
// On errors, default to systemd
runsUnderSystemd := err != nil || string(initCommand) == "systemd"
unitName := fmt.Sprintf("podman-%d.scope", os.Getpid())
if conf.Engine.CgroupManager == config.SystemdCgroupsManager {
if runsUnderSystemd || conf.Engine.CgroupManager == config.SystemdCgroupsManager {
if err := utils.RunUnderSystemdScope(os.Getpid(), "user.slice", unitName); err != nil {
logrus.Warnf("Failed to add podman to systemd sandbox cgroup: %v", err)
}