Skip to content

Commit

Permalink
CA-405454: Update move_to_root_cgroup to work with cgroup v2
Browse files Browse the repository at this point in the history
The previous logic was only compatible with cgroup v1, update so we also work
with cgroup v2 if present on the system.

Signed-off-by: Alex Brett <[email protected]>
  • Loading branch information
alexbrett committed Jan 30, 2025
1 parent e42adb4 commit ae864a3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,25 @@ main_terminate(

static void move_to_root_cgroup(void) {
FILE *f;
const char *cgroup_task_fname = NULL;

f = fopen("/sys/fs/cgroup/cpu/tasks", "w");
// Determine if we are using cgroup v1 or v2
f = fopen("/sys/fs/cgroup/cpu/cpu.rt_runtime_us", "rt");
if (f == NULL) {
// Try cgroup v2
f = fopen("/sys/fs/cgroup/cgroup.procs", "rt");
if (f == NULL) {
log_message(LOG_WARNING, "cpu.rt_runtime_us and cgroup.procs don't exist!\n");
return;
} else {
cgroup_task_fname = "/sys/fs/cgroup/cgroup.procs";
}
} else {
cgroup_task_fname = "/sys/fs/cgroup/cpu/tasks";
}
(void)fclose(f);

f = fopen(cgroup_task_fname, "w");
if (f == NULL) {
log_message(LOG_WARNING, "Can't open cgroups tasks file for writing (sys %d)\n", errno);
return;
Expand Down

0 comments on commit ae864a3

Please sign in to comment.