Skip to content

Commit

Permalink
cgroups: use cgroup.controllers to read controllers
Browse files Browse the repository at this point in the history
use the cgroup.controllers file instead of cgroup.subtree_control to
read the list of controllers available in the current cgroup.

Closes: containers#11931

[NO TESTS NEEDED] we have disabled this test in the CI because it is
difficult to know what controllers are going to be enabled for
rootless under all conditions we test.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe authored and mheon committed Oct 19, 2021
1 parent 8b87793 commit b470de0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ func init() {
func getAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]controller, error) {
if cgroup2 {
controllers := []controller{}
subtreeControl := cgroupRoot + "/cgroup.subtree_control"
// rootless cgroupv2: check available controllers for current user ,systemd or servicescope will inherit
controllersFile := cgroupRoot + "/cgroup.controllers"
// rootless cgroupv2: check available controllers for current user, systemd or servicescope will inherit
if rootless.IsRootless() {
userSlice, err := getCgroupPathForCurrentProcess()
if err != nil {
return controllers, err
}
//userSlice already contains '/' so not adding here
basePath := cgroupRoot + userSlice
subtreeControl = fmt.Sprintf("%s/cgroup.subtree_control", basePath)
controllersFile = fmt.Sprintf("%s/cgroup.controllers", basePath)
}
subtreeControlBytes, err := ioutil.ReadFile(subtreeControl)
controllersFileBytes, err := ioutil.ReadFile(controllersFile)
if err != nil {
return nil, errors.Wrapf(err, "failed while reading controllers for cgroup v2 from %q", subtreeControl)
return nil, errors.Wrapf(err, "failed while reading controllers for cgroup v2 from %q", controllersFile)
}
for _, controllerName := range strings.Fields(string(subtreeControlBytes)) {
for _, controllerName := range strings.Fields(string(controllersFileBytes)) {
c := controller{
name: controllerName,
symlink: false,
Expand Down

0 comments on commit b470de0

Please sign in to comment.