Merge pull request #7339 from giuseppe/change-systemd-detection

abi: fix detection for systemd
This commit is contained in:
OpenShift Merge Robot
2020-08-18 20:49:45 +02:00
committed by GitHub

View File

@ -70,8 +70,13 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command)
if err != nil { if err != nil {
return err 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()) 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 { if err := utils.RunUnderSystemdScope(os.Getpid(), "user.slice", unitName); err != nil {
logrus.Warnf("Failed to add podman to systemd sandbox cgroup: %v", err) logrus.Warnf("Failed to add podman to systemd sandbox cgroup: %v", err)
} }