initialize initializes the specified hierarchy
()
| 291 | |
| 292 | // initialize initializes the specified hierarchy |
| 293 | func (c *CgroupControl) initialize() (err error) { |
| 294 | createdSoFar := map[string]controllerHandler{} |
| 295 | defer func() { |
| 296 | if err != nil { |
| 297 | for name, ctr := range createdSoFar { |
| 298 | if err := ctr.Destroy(c); err != nil { |
| 299 | logrus.Warningf("error cleaning up controller %s for %s", name, c.path) |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | }() |
| 304 | if c.cgroup2 { |
| 305 | if err := createCgroupv2Path(filepath.Join(cgroupRoot, c.path)); err != nil { |
| 306 | return errors.Wrapf(err, "error creating cgroup path %s", c.path) |
| 307 | } |
| 308 | } |
| 309 | for name, handler := range handlers { |
| 310 | created, err := handler.Create(c) |
| 311 | if err != nil { |
| 312 | return err |
| 313 | } |
| 314 | if created { |
| 315 | createdSoFar[name] = handler |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | if !c.cgroup2 { |
| 320 | // We won't need to do this for cgroup v2 |
| 321 | for _, ctr := range c.additionalControllers { |
| 322 | if ctr.symlink { |
| 323 | continue |
| 324 | } |
| 325 | path := c.getCgroupv1Path(ctr.name) |
| 326 | if err := os.MkdirAll(path, 0755); err != nil { |
| 327 | return errors.Wrapf(err, "error creating cgroup path for %s", ctr.name) |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | return nil |
| 333 | } |
| 334 | |
| 335 | func (c *CgroupControl) createCgroupDirectory(controller string) (bool, error) { |
| 336 | cPath := c.getCgroupv1Path(controller) |
no test coverage detected