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