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.hroma...@oracle.com>
---
 src/api.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/api.c b/src/api.c
index 9cfb42aaa112..bef9ea263f43 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.25.3



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to