]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
From: Ivana Hutarova Varekova <varekova@redhat.com>
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 10 May 2012 05:07:41 +0000 (07:07 +0200)
committerIvana Hutarova Varekova <varekova@redhat.com>
Thu, 10 May 2012 05:07:41 +0000 (07:07 +0200)
lscgroup: fix path name trimming

lscgroup tool in display_controller_data procedure trimmed relative path
name too strictly, thus if the path have no leading "/" sign then the first
character was trimmed too.

More precisely the relative path is taken from the full path - path to the
controller root and relative path given on command line (with all
characters "/") + character "/" at the end of path. The length of suffix
which describe relative path is count from trimmed relative path given on
command line (without characters "/" at the beginning and at the end).
There have to be used the same relative path in both cases and -1 to the
length.

CHANGELOG v1:
* more detailed description
* fix the problem with "/" sign at the end of path too

EXAMPLE
without the patch:
$ lscgroup freezer:libvirt
freezer:/ibvirt/
freezer:/ibvirt/lxc
freezer:/ibvirt/qemu

with the patch:
$ lscgroup freezer:libvirt
freezer:/libvirt/
freezer:/libvirt/lxc
freezer:/libvirt/qemu

this patch fixes the problem.

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

index 6ab2103c707be613a3803e9b053413b0d5568bec..c16f193bc2d60b1dc45d0238964b5710d5bf4eab 100644 (file)
@@ -91,16 +91,16 @@ static int display_controller_data(char *input_path, char *controller, char *nam
        int lvl;
        int len;
 
-       ret = cgroup_walk_tree_begin(controller, input_path, 0,
+       strncpy(input_dir_path, input_path, FILENAME_MAX);
+       /* remove problematic  '/' characters from input path */
+       trim_filepath(input_dir_path);
+
+       ret = cgroup_walk_tree_begin(controller, input_dir_path, 0,
                &handle, &info, &lvl);
        if (ret != 0)
                return ret;
 
-       strncpy(input_dir_path, input_path, FILENAME_MAX);
-       /* remove problematic  '/' characters from input path*/
-       trim_filepath(input_dir_path);
-
-       len  = strlen(info.full_path) - strlen(input_dir_path);
+       len  = strlen(info.full_path) - strlen(input_dir_path) - 1;
        print_info(&info, name, len);
        while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) == 0)
                print_info(&info, name, len);