mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
cgroupv2: move sanity path check to common code
The fs2 cgroup driver has a sanity check for path. Since systemd driver is relying on the same path, it makes sense to move this check to the common code. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -30,11 +30,7 @@ func NewManager(config *configs.Cgroup, dirPath string, rootless bool) (cgroups.
|
|||||||
if config == nil {
|
if config == nil {
|
||||||
config = &configs.Cgroup{}
|
config = &configs.Cgroup{}
|
||||||
}
|
}
|
||||||
if dirPath != "" {
|
if dirPath == "" {
|
||||||
if filepath.Clean(dirPath) != dirPath || !filepath.IsAbs(dirPath) {
|
|
||||||
return nil, errors.Errorf("invalid dir path %q", dirPath)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var err error
|
var err error
|
||||||
dirPath, err = defaultDirPath(config)
|
dirPath, err = defaultDirPath(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -51,16 +51,22 @@ func InitArgs(args ...string) func(*LinuxFactory) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getUnifiedPath(paths map[string]string) string {
|
func getUnifiedPath(paths map[string]string) string {
|
||||||
unifiedPath := ""
|
path := ""
|
||||||
for k, v := range paths {
|
for k, v := range paths {
|
||||||
if unifiedPath == "" {
|
if path == "" {
|
||||||
unifiedPath = v
|
path = v
|
||||||
} else if v != unifiedPath {
|
} else if v != path {
|
||||||
panic(errors.Errorf("expected %q path to be unified path %q, got %q", k, unifiedPath, v))
|
panic(errors.Errorf("expected %q path to be unified path %q, got %q", k, path, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// can be empty
|
// can be empty
|
||||||
return unifiedPath
|
if path != "" {
|
||||||
|
if filepath.Clean(path) != path || !filepath.IsAbs(path) {
|
||||||
|
panic(errors.Errorf("invalid dir path %q", path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func systemdCgroupV2(l *LinuxFactory, rootless bool) error {
|
func systemdCgroupV2(l *LinuxFactory, rootless bool) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user