Merge pull request #3731 from giuseppe/fix-systemd-in-a-container

cgroup: fix regression when running systemd
This commit is contained in:
OpenShift Merge Robot
2019-08-07 04:50:13 +02:00
committed by GitHub

View File

@ -471,9 +471,9 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
return err return err
} }
g.RemoveMount("/sys/fs/cgroup")
if unified { if unified {
g.RemoveMount("/sys/fs/cgroup")
sourcePath := filepath.Join("/sys/fs/cgroup") sourcePath := filepath.Join("/sys/fs/cgroup")
systemdMnt := spec.Mount{ systemdMnt := spec.Mount{
Destination: "/sys/fs/cgroup", Destination: "/sys/fs/cgroup",
@ -483,31 +483,13 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
} }
g.AddMount(systemdMnt) g.AddMount(systemdMnt)
} else { } else {
// rootless containers have no write access to /sys/fs/cgroup, so don't systemdMnt := spec.Mount{
// add any mount into the container. Destination: "/sys/fs/cgroup/systemd",
if !rootless.IsRootless() { Type: "bind",
cgroupPath, err := c.CGroupPath() Source: "/sys/fs/cgroup/systemd",
if err != nil { Options: []string{"bind", "nodev", "noexec", "nosuid"},
return err
}
sourcePath := filepath.Join("/sys/fs/cgroup", cgroupPath)
systemdMnt := spec.Mount{
Destination: "/sys/fs/cgroup",
Type: "bind",
Source: sourcePath,
Options: []string{"bind", "private"},
}
g.AddMount(systemdMnt)
} else {
systemdMnt := spec.Mount{
Destination: "/sys/fs/cgroup",
Type: "bind",
Source: "/sys/fs/cgroup",
Options: []string{"bind", "nodev", "noexec", "nosuid"},
}
g.AddMount(systemdMnt)
} }
g.AddMount(systemdMnt)
} }
return nil return nil