From: Ivana Hutarova Varekova Date: Thu, 10 May 2012 05:07:41 +0000 (+0200) Subject: From: Ivana Hutarova Varekova X-Git-Tag: v0.41~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c741b742bd0707f5ab58e6a29196eab42080a233;p=thirdparty%2Flibcgroup.git From: Ivana Hutarova Varekova 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 Acked-By: Jan Safranek --- diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index 6ab2103c..c16f193b 100644 --- a/src/tools/lscgroup.c +++ b/src/tools/lscgroup.c @@ -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);