writeCgroupProcs writes to the file, but retries on EINVAL.
(path string, content []byte, perm fs.FileMode)
| 198 | |
| 199 | // writeCgroupProcs writes to the file, but retries on EINVAL. |
| 200 | func 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 | |
| 224 | func (c *cgroup) add(process Process, pType procType, subsystems ...Name) error { |
| 225 | if process.Pid <= 0 { |
no outgoing calls
no test coverage detected
searching dependent graphs…