]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: Only stat the cgroup tasks file if it's a v1 mount
authorTom Hromatka <tom.hromatka@oracle.com>
Mon, 11 May 2020 02:16:42 +0000 (02:16 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 16 Jun 2020 14:43:30 +0000 (08:43 -0600)
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 <tom.hromatka@oracle.com>
Acked-by: Dhaval Giani <dhaval.giani@oracle.com>
src/api.c

index 9cfb42aaa112bc88017072248db45c48dc6d5501..bef9ea263f43b6316d60aba01edbeecfd95354d2 100644 (file)
--- 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);