Skip to content

Commit ddda8a1

Browse files
authored
Merge pull request #204 from shankerwangmiao/main
Improvements on cgroup v2 support
2 parents fbc4dd0 + 73a8516 commit ddda8a1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

v2/manager.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ func (c *Manager) ToggleControllers(controllers []string, t ControllerToggle) er
272272
// controller is already written.
273273
// So we only return the last error.
274274
lastErr = errors.Wrapf(err, "failed to write subtree controllers %+v to %q", controllers, filePath)
275+
} else {
276+
lastErr = nil
275277
}
276278
}
277279
return lastErr
@@ -301,15 +303,23 @@ func (c *Manager) NewChild(name string, resources *Resources) (*Manager, error)
301303
if err := os.MkdirAll(path, defaultDirPerm); err != nil {
302304
return nil, err
303305
}
306+
m := Manager{
307+
unifiedMountpoint: c.unifiedMountpoint,
308+
path: path,
309+
}
310+
if resources != nil {
311+
if err := m.ToggleControllers(resources.EnabledControllers(), Enable); err != nil {
312+
// clean up cgroup dir on failure
313+
os.Remove(path)
314+
return nil, err
315+
}
316+
}
304317
if err := setResources(path, resources); err != nil {
305318
// clean up cgroup dir on failure
306319
os.Remove(path)
307320
return nil, err
308321
}
309-
return &Manager{
310-
unifiedMountpoint: c.unifiedMountpoint,
311-
path: path,
312-
}, nil
322+
return &m, nil
313323
}
314324

315325
func (c *Manager) AddProc(pid uint64) error {

0 commit comments

Comments
 (0)