MCPcopy Create free account
hub / github.com/containers/common / Load

Function Load

pkg/cgroups/cgroups.go:432–471  ·  view source on GitHub ↗

Load loads an existing cgroup control

(path string)

Source from the content-addressed store, hash-verified

430
431// Load loads an existing cgroup control
432func Load(path string) (*CgroupControl, error) {
433 cgroup2, err := IsCgroup2UnifiedMode()
434 if err != nil {
435 return nil, err
436 }
437 control := &CgroupControl{
438 cgroup2: cgroup2,
439 path: path,
440 systemd: false,
441 }
442 if !cgroup2 {
443 controllers, err := getAvailableControllers(handlers, false)
444 if err != nil {
445 return nil, err
446 }
447 control.additionalControllers = controllers
448 }
449 if !cgroup2 {
450 oneExists := false
451 // check that the cgroup exists at least under one controller
452 for name := range handlers {
453 p := control.getCgroupv1Path(name)
454 if _, err := os.Stat(p); err == nil {
455 oneExists = true
456 break
457 }
458 }
459
460 // if there is no controller at all, raise an error
461 if !oneExists {
462 if unshare.IsRootless() {
463 return nil, ErrCgroupV1Rootless
464 }
465 // compatible with the error code
466 // used by containerd/cgroups
467 return nil, ErrCgroupDeleted
468 }
469 }
470 return control, nil
471}
472
473// CreateSystemdUnit creates the systemd cgroup
474func (c *CgroupControl) CreateSystemdUnit(path string) error {

Callers

nothing calls this directly

Calls 4

getCgroupv1PathMethod · 0.95
getAvailableControllersFunction · 0.85
IsCgroup2UnifiedModeFunction · 0.70
StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…