mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
Add validation for CGroup parents. Pass CGroups path into runc
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #507 Approved by: baude
This commit is contained in:
@ -3,6 +3,7 @@ package libpod
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@ -60,6 +61,24 @@ func (r *Runtime) NewContainer(ctx context.Context, rSpec *spec.Spec, options ..
|
||||
ctr.config.Name = name
|
||||
}
|
||||
|
||||
// Check CGroup parent sanity, and set it if it was not set
|
||||
switch r.config.CgroupManager {
|
||||
case CgroupfsCgroupsManager:
|
||||
if ctr.config.CgroupParent == "" {
|
||||
ctr.config.CgroupParent = CgroupfsDefaultCgroupParent
|
||||
} else if strings.HasSuffix(path.Base(ctr.config.CgroupParent), ".slice") {
|
||||
return nil, errors.Wrapf(ErrInvalidArg, "systemd slice received as cgroup parent when using cgroupfs")
|
||||
}
|
||||
case SystemdCgroupsManager:
|
||||
if ctr.config.CgroupParent == "" {
|
||||
ctr.config.CgroupParent = SystemdDefaultCgroupParent
|
||||
} else if len(ctr.config.CgroupParent) < 6 || !strings.HasSuffix(path.Base(ctr.config.CgroupParent), ".slice") {
|
||||
return nil, errors.Wrapf(ErrInvalidArg, "did not receive systemd slice as cgroup parent when using systemd to manage cgroups")
|
||||
}
|
||||
default:
|
||||
return nil, errors.Wrapf(ErrInvalidArg, "unsupported CGroup manager: %s - cannot validate cgroup parent", r.config.CgroupManager)
|
||||
}
|
||||
|
||||
// Set up storage for the container
|
||||
if err := ctr.setupStorage(ctx); err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user