@@ -19,7 +19,6 @@ package fs2
1919import (
2020 "bufio"
2121 "errors"
22- "fmt"
2322 "io"
2423 "os"
2524 "path/filepath"
@@ -33,26 +32,19 @@ const UnifiedMountpoint = "/sys/fs/cgroup"
3332
3433func defaultDirPath (c * cgroups.Cgroup ) (string , error ) {
3534 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 != "" {
4435 return "" , errors .New ("cgroup: either Path or Name and Parent should be used" )
4536 }
4637
4738 // XXX: Do not remove CleanPath. Path safety is important! -- cyphar
48- innerPath := utils .CleanPath (cgPath )
39+ innerPath := utils .CleanPath (c . Path )
4940 if innerPath == "" {
50- cgParent := utils .CleanPath (cgParent )
51- cgName := utils .CleanPath (cgName )
41+ cgParent := utils .CleanPath (c . Parent )
42+ cgName := utils .CleanPath (c . Name )
5243 innerPath = filepath .Join (cgParent , cgName )
5344 }
45+
5446 if filepath .IsAbs (innerPath ) {
55- return filepath .Join (root , innerPath ), nil
47+ return filepath .Join (UnifiedMountpoint , innerPath ), nil
5648 }
5749
5850 // we don't need to use /proc/thread-self here because runc always runs
@@ -67,7 +59,7 @@ func _defaultDirPath(root, cgPath, cgParent, cgName string) (string, error) {
6759 // A parent cgroup (with no tasks in it) is what we need.
6860 ownCgroup = filepath .Dir (ownCgroup )
6961
70- return filepath .Join (root , ownCgroup , innerPath ), nil
62+ return filepath .Join (UnifiedMountpoint , ownCgroup , innerPath ), nil
7163}
7264
7365// parseCgroupFile parses /proc/PID/cgroup file and return string
0 commit comments