In cgroup_get_cgroup(), populate the controller list in the cgroup
only with controllers that are enabled in cgroup.subtree_control.
As part of this change update the error codes from
cgroupv2_get_subtree_control() to better reflect memory allocation
errors
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
*enabled = false;
path_copy = (char *)malloc(FILENAME_MAX);
- if (!path_copy)
+ if (!path_copy) {
+ error = ECGOTHER;
goto out;
+ }
ret = snprintf(path_copy, FILENAME_MAX, "%s/%s", path, CGV2_SUBTREE_CTRL_FILE);
- if (ret < 0)
+ if (ret < 0) {
+ error = ECGOTHER;
goto out;
+ }
fp = fopen(path_copy, "re");
if (!fp) {
cgroup_warn("fopen failed\n");
last_errno = errno;
+ error = ECGOTHER;
goto out;
}
cgroup->tasks_gid = stat_buffer.st_gid;
free(control_path);
+ } else { /* cgroup v2 */
+ bool enabled;
+
+ error = cgroupv2_get_subtree_control(path, cg_mount_table[i].name,
+ &enabled);
+ if (error == ECGROUPNOTMOUNTED)
+ continue;
+ if (error)
+ goto unlock_error;
+
+ if (!enabled)
+ continue;
}
cgc = cgroup_add_controller(cgroup, cg_mount_table[i].name);