@@ -19,40 +19,25 @@ package fs2
1919import (
2020 "bufio"
2121 "errors"
22- "fmt"
2322 "io"
2423 "os"
2524 "path/filepath"
2625 "strings"
2726
2827 "github.com/opencontainers/runc/libcontainer/cgroups"
29- "github.com/opencontainers/runc/libcontainer/utils "
28+ "github.com/opencontainers/runc/libcontainer/cgroups/internal/path "
3029)
3130
3231const UnifiedMountpoint = "/sys/fs/cgroup"
3332
3433func defaultDirPath (c * cgroups.Cgroup ) (string , error ) {
35- if (c .Name != "" || c .Parent != "" ) && c .Path != "" {
36- return "" , fmt .Errorf ("cgroup: either Path or Name and Parent should be used, got %+v" , c )
37- }
38-
39- return _defaultDirPath (UnifiedMountpoint , c .Path , c .Parent , c .Name )
40- }
41-
42- func _defaultDirPath (root , cgPath , cgParent , cgName string ) (string , error ) {
43- if (cgName != "" || cgParent != "" ) && cgPath != "" {
44- return "" , errors .New ("cgroup: either Path or Name and Parent should be used" )
34+ innerPath , err := path .Inner (c )
35+ if err != nil {
36+ return "" , err
4537 }
4638
47- // XXX: Do not remove CleanPath. Path safety is important! -- cyphar
48- innerPath := utils .CleanPath (cgPath )
49- if innerPath == "" {
50- cgParent := utils .CleanPath (cgParent )
51- cgName := utils .CleanPath (cgName )
52- innerPath = filepath .Join (cgParent , cgName )
53- }
5439 if filepath .IsAbs (innerPath ) {
55- return filepath .Join (root , innerPath ), nil
40+ return filepath .Join (UnifiedMountpoint , innerPath ), nil
5641 }
5742
5843 // we don't need to use /proc/thread-self here because runc always runs
@@ -67,7 +52,7 @@ func _defaultDirPath(root, cgPath, cgParent, cgName string) (string, error) {
6752 // A parent cgroup (with no tasks in it) is what we need.
6853 ownCgroup = filepath .Dir (ownCgroup )
6954
70- return filepath .Join (root , ownCgroup , innerPath ), nil
55+ return filepath .Join (UnifiedMountpoint , ownCgroup , innerPath ), nil
7156}
7257
7358// parseCgroupFile parses /proc/PID/cgroup file and return string
0 commit comments