MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / newCgroup

Function newCgroup

pkg/init/cmd/service/prepare.go:123–151  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
123func 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
153func isCgroupV2() (bool, error) {
154 _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers")

Callers 1

prepareFilesystemFunction · 0.85

Calls 1

isCgroupV2Function · 0.85

Tested by

no test coverage detected