()
| 320 | } |
| 321 | |
| 322 | func (p *setnsProcess) addIntoCgroupV2() error { |
| 323 | sub := p.process.SubCgroupPaths[""] |
| 324 | err := p.manager.AddPid(sub, p.pid()) |
| 325 | if err == nil { |
| 326 | return nil |
| 327 | } |
| 328 | |
| 329 | // Failed to join the configured cgroup. Fall back to container init's cgroup |
| 330 | // unless sub-cgroup is explicitly requested. |
| 331 | var path string |
| 332 | if sub != "" { |
| 333 | goto fail |
| 334 | } |
| 335 | path = p.initProcessCgroupPath() |
| 336 | if path == "" { |
| 337 | goto fail |
| 338 | } |
| 339 | logrus.Debugf("adding pid %d to configured cgroup failed (%v), will join container init cgroup %q", p.pid(), err, path) |
| 340 | // NOTE: path is not guaranteed to exist because we didn't pause the container. |
| 341 | err = cgroups.WriteCgroupProc(path, p.pid()) |
| 342 | if err != nil { |
| 343 | goto fail |
| 344 | } |
| 345 | return nil |
| 346 | |
| 347 | fail: |
| 348 | if p.rootlessCgroups { |
| 349 | // Ignore cgroup join errors when rootless. |
| 350 | return nil |
| 351 | } |
| 352 | |
| 353 | return fmt.Errorf("error adding pid %d to cgroups: %w", p.pid(), err) |
| 354 | } |
| 355 | |
| 356 | func (p *setnsProcess) addIntoCgroup() error { |
| 357 | if p.cmd.SysProcAttr.UseCgroupFD { |
no test coverage detected