...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package cgroups
17
18 import (
19 "errors"
20 "fmt"
21 "os"
22
23 "github.com/containerd/cgroups"
24 )
25
26 func V1() ([]cgroups.Subsystem, error) {
27 subsystems, err := defaults("/host-sys/fs/cgroup")
28 if err != nil {
29 return nil, err
30 }
31 var enabled []cgroups.Subsystem
32 for _, s := range pathers(subsystems) {
33
34 if _, err := os.Lstat(s.Path("/")); err == nil {
35 enabled = append(enabled, s)
36 }
37 }
38 return enabled, nil
39 }
40
41 func PidPath(pid int) cgroups.Path {
42 p := fmt.Sprintf("/proc/%d/cgroup", pid)
43 paths, err := cgroups.ParseCgroupFile(p)
44 if err != nil {
45 return func(_ cgroups.Name) (string, error) {
46 return "", fmt.Errorf("failed to parse cgroup file %s: %s", p, err.Error())
47 }
48 }
49
50 return func(name cgroups.Name) (string, error) {
51 root, ok := paths[string(name)]
52 if !ok {
53 if root, ok = paths["name="+string(name)]; !ok {
54 return "", errors.New("controller is not supported")
55 }
56 }
57
58 return root, nil
59 }
60 }
61