]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
fixes the cgsnapshot problem with pfile permisssions
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 25 Oct 2010 10:27:08 +0000 (12:27 +0200)
committerJan Safranek <jsafrane@redhat.com>
Tue, 26 Oct 2010 06:36:16 +0000 (08:36 +0200)
cgpconfigparser changes the permissions of all files. That's why to test whether the variable file is writable, there have to be used the variable file from the root group.

  CHANGELOG:
* add the information why root group is used for finding which variable is writable

Signed-off-by: Ivana Hutarova Varekova<varekova@redhat.com>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
src/tools/cgsnapshot.c

index a593f91a747b1b3c8222ee8f8fa0c4643fc40a58..f347b39341421679ea3d4713f4d69b221967366f 100644 (file)
@@ -273,7 +273,7 @@ static int display_permissions(const char *path,
 
 static int display_cgroup_data(struct cgroup *group,
                char controller[CG_CONTROLLER_MAX][FILENAME_MAX],
-               const char *group_path, int first,
+               const char *group_path, int root_path_len, int first,
                const char *program_name)
 {
        int i = 0, j;
@@ -315,8 +315,14 @@ static int display_cgroup_data(struct cgroup *group,
                for (j = 0; j < nr_var; j++) {
                        name = cgroup_get_value_name(group_controller, j);
 
-                       /* test whether the variable file is writable */
-                       strncpy(var_path, group_path, FILENAME_MAX);
+                       /* For the non-root groups cgconfigparser set
+                          permissions of variable files to 777. Thus
+                          It is necessary to test the permissions of
+                          variable files in the root group to find out
+                          whether the variable is writable.
+                        */
+                       strncpy(var_path, group_path, root_path_len);
+                       var_path[root_path_len] = '\0';
                        strncat(var_path, "/", FILENAME_MAX);
                        var_path[FILENAME_MAX-1] = '\0';
                        strncat(var_path, name, FILENAME_MAX);
@@ -450,7 +456,7 @@ static int display_controller_data(
                        }
 
                        display_cgroup_data(group, controller, info.full_path,
-                               first, program_name);
+                               prefix_len, first, program_name);
                        first = 0;
                }
        }