From e09283cb138aa1d97079b936330230fc0ed7a730 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Mon, 11 May 2020 02:16:42 +0000 Subject: [PATCH] api.c: Only stat the cgroup tasks file if it's a v1 mount In cgroup_get_cgroup(), stat should only be called on the cgroup's task file if the cgroup is a v1 mount. v2 mounts don't have a tasks file. Signed-off-by: Tom Hromatka Acked-by: Dhaval Giani --- src/api.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/api.c b/src/api.c index 9cfb42aa..bef9ea26 100644 --- a/src/api.c +++ b/src/api.c @@ -2688,25 +2688,27 @@ int cgroup_get_cgroup(struct cgroup *cgroup) * Get the uid and gid information */ - ret = asprintf(&control_path, "%s/tasks", path); + if (cg_mount_table[i].version == CGROUP_V1) { + ret = asprintf(&control_path, "%s/tasks", path); - if (ret < 0) { - last_errno = errno; - error = ECGOTHER; - goto unlock_error; - } + if (ret < 0) { + last_errno = errno; + error = ECGOTHER; + goto unlock_error; + } - if (stat(control_path, &stat_buffer)) { - last_errno = errno; - free(control_path); - error = ECGOTHER; - goto unlock_error; - } + if (stat(control_path, &stat_buffer)) { + last_errno = errno; + free(control_path); + error = ECGOTHER; + goto unlock_error; + } - cgroup->tasks_uid = stat_buffer.st_uid; - cgroup->tasks_gid = stat_buffer.st_gid; + cgroup->tasks_uid = stat_buffer.st_uid; + cgroup->tasks_gid = stat_buffer.st_gid; - free(control_path); + free(control_path); + } cgc = cgroup_add_controller(cgroup, cg_mount_table[i].name); -- 2.47.2