{
struct dirent *ctrl_dir = NULL;
int initial_controller_cnt;
+ int controller_cnt = 0;
char *control_path = NULL;
char path[FILENAME_MAX];
DIR *dir = NULL;
* and we've made it this far, then they are explicitly
* interested in this controller and we should not remove it.
*/
- if (initial_controller_cnt == 0)
+ if (initial_controller_cnt == 0) {
+ controller_cnt++;
continue;
+ }
} else if (error) {
goto unlock_error;
}
goto unlock_error;
}
+ controller_cnt++;
+
while ((ctrl_dir = readdir(dir)) != NULL) {
/* Skip over non regular files */
if (ctrl_dir->d_type != DT_REG)
}
}
- /* Check if the group really exists or not */
- if (!cgroup->index) {
+ /*
+ * Check if the group really exists or not. The cgroup->index controller count can't
+ * be used in this case because cgroup v2 allows controllers to be enabled/disabled in
+ * the subtree_control file. Rather, cgroup_get_cgroup() tracks the number of possible
+ * controllers in the controller_cnt variable and uses that to determine if the cgroup
+ * exists or not.
+ */
+ if (!controller_cnt) {
error = ECGROUPNOTEXIST;
goto unlock_error;
}