MCPcopy Create free account
hub / github.com/containerd/cgroups / writeCgroupProcs

Function writeCgroupProcs

cgroup1/cgroup.go:200–222  ·  view source on GitHub ↗

writeCgroupProcs writes to the file, but retries on EINVAL.

(path string, content []byte, perm fs.FileMode)

Source from the content-addressed store, hash-verified

198
199// writeCgroupProcs writes to the file, but retries on EINVAL.
200func writeCgroupProcs(path string, content []byte, perm fs.FileMode) error {
201 f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, perm)
202 if err != nil {
203 return err
204 }
205 defer f.Close()
206
207 for i := 0; i < 5; i++ {
208 _, err = f.Write(content)
209 if err == nil {
210 return nil
211 }
212 // If the process's associated task's state is TASK_NEW, the kernel
213 // returns EINVAL. The function will retry on the error like runc.
214 // https://github.com/torvalds/linux/blob/v6.0/kernel/sched/core.c#L10308-L10337
215 // https://github.com/opencontainers/runc/pull/1950
216 if !errors.Is(err, syscall.EINVAL) {
217 return err
218 }
219 time.Sleep(30 * time.Millisecond)
220 }
221 return err
222}
223
224func (c *cgroup) add(process Process, pType procType, subsystems ...Name) error {
225 if process.Pid <= 0 {

Callers 1

addMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…