newCgroup creates a cgroup (ie directory) we could use github.com/containerd/cgroups but it has a lot of deps and this is just a sugary mkdir
(cgroup string)
| 121 | // newCgroup creates a cgroup (ie directory) |
| 122 | // we could use github.com/containerd/cgroups but it has a lot of deps and this is just a sugary mkdir |
| 123 | func newCgroup(cgroup string) error { |
| 124 | v2, err := isCgroupV2() |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | if v2 { |
| 129 | // a cgroupv2 cgroup is a single directory |
| 130 | if err := os.MkdirAll(filepath.Join("/sys/fs/cgroup", cgroup), 0755); err != nil { |
| 131 | log.Printf("cgroup error: %v", err) |
| 132 | } |
| 133 | return nil |
| 134 | } |
| 135 | // a cgroupv1 cgroup is a directory under all directories in /sys/fs/cgroup |
| 136 | dirs, err := os.ReadDir("/sys/fs/cgroup") |
| 137 | if err != nil { |
| 138 | return err |
| 139 | } |
| 140 | |
| 141 | for _, dir := range dirs { |
| 142 | if !dir.IsDir() { |
| 143 | continue |
| 144 | } |
| 145 | if err := os.MkdirAll(filepath.Join("/sys/fs/cgroup", dir.Name(), cgroup), 0755); err != nil { |
| 146 | log.Printf("cgroup error: %v", err) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | return nil |
| 151 | } |
| 152 | |
| 153 | func isCgroupV2() (bool, error) { |
| 154 | _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers") |
no test coverage detected