Load will load an existing cgroup and allow it to be controlled All static path should not include `/sys/fs/cgroup/` prefix, it should start with your own cgroups name
(path Path, opts ...InitOpts)
| 72 | // Load will load an existing cgroup and allow it to be controlled |
| 73 | // All static path should not include `/sys/fs/cgroup/` prefix, it should start with your own cgroups name |
| 74 | func Load(path Path, opts ...InitOpts) (Cgroup, error) { |
| 75 | config := newInitConfig() |
| 76 | for _, o := range opts { |
| 77 | if err := o(config); err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | } |
| 81 | var activeSubsystems []Subsystem |
| 82 | subsystems, err := config.hierarchy() |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | // check that the subsystems still exist, and keep only those that actually exist |
| 87 | for _, s := range pathers(subsystems) { |
| 88 | p, err := path(s.Name()) |
| 89 | if err != nil { |
| 90 | if errors.Is(err, os.ErrNotExist) { |
| 91 | return nil, ErrCgroupDeleted |
| 92 | } |
| 93 | if err == ErrControllerNotActive { |
| 94 | if config.InitCheck != nil { |
| 95 | if skerr := config.InitCheck(s, path, err); skerr != nil { |
| 96 | if skerr != ErrIgnoreSubsystem { |
| 97 | return nil, skerr |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | continue |
| 102 | } |
| 103 | return nil, err |
| 104 | } |
| 105 | if _, err := os.Lstat(s.Path(p)); err != nil { |
| 106 | if os.IsNotExist(err) { |
| 107 | continue |
| 108 | } |
| 109 | return nil, err |
| 110 | } |
| 111 | activeSubsystems = append(activeSubsystems, s) |
| 112 | } |
| 113 | // if we do not have any active systems then the cgroup is deleted |
| 114 | if len(activeSubsystems) == 0 { |
| 115 | return nil, ErrCgroupDeleted |
| 116 | } |
| 117 | return &cgroup{ |
| 118 | path: path, |
| 119 | subsystems: activeSubsystems, |
| 120 | }, nil |
| 121 | } |
| 122 | |
| 123 | type cgroup struct { |
| 124 | path Path |
searching dependent graphs…