Load loads an existing cgroup control
(path string)
| 430 | |
| 431 | // Load loads an existing cgroup control |
| 432 | func 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 |
| 474 | func (c *CgroupControl) CreateSystemdUnit(path string) error { |
nothing calls this directly
no test coverage detected
searching dependent graphs…