MCPcopy
hub / github.com/opencontainers/runc / addIntoCgroupV2

Method addIntoCgroupV2

libcontainer/process_linux.go:322–354  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

320}
321
322func (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
347fail:
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
356func (p *setnsProcess) addIntoCgroup() error {
357 if p.cmd.SysProcAttr.UseCgroupFD {

Callers 1

addIntoCgroupMethod · 0.95

Calls 3

initProcessCgroupPathMethod · 0.95
AddPidMethod · 0.80
pidMethod · 0.65

Tested by

no test coverage detected