@@ -19,40 +19,25 @@ package fs2
19
19
import (
20
20
"bufio"
21
21
"errors"
22
- "fmt"
23
22
"io"
24
23
"os"
25
24
"path/filepath"
26
25
"strings"
27
26
28
27
"github.com/opencontainers/runc/libcontainer/cgroups"
29
- "github.com/opencontainers/runc/libcontainer/utils "
28
+ "github.com/opencontainers/runc/libcontainer/cgroups/internal/path "
30
29
)
31
30
32
31
const UnifiedMountpoint = "/sys/fs/cgroup"
33
32
34
33
func 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
45
37
}
46
38
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
- }
54
39
if filepath .IsAbs (innerPath ) {
55
- return filepath .Join (root , innerPath ), nil
40
+ return filepath .Join (UnifiedMountpoint , innerPath ), nil
56
41
}
57
42
58
43
// 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) {
67
52
// A parent cgroup (with no tasks in it) is what we need.
68
53
ownCgroup = filepath .Dir (ownCgroup )
69
54
70
- return filepath .Join (root , ownCgroup , innerPath ), nil
55
+ return filepath .Join (UnifiedMountpoint , ownCgroup , innerPath ), nil
71
56
}
72
57
73
58
// parseCgroupFile parses /proc/PID/cgroup file and return string
0 commit comments