From: Ivana Hutarova Varekova Date: Fri, 22 Jun 2012 19:13:56 +0000 (+0200) Subject: lscgroup: don't trim "/" X-Git-Tag: v0.41~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbdb244594014f71676f26c3418d3b2479306101;p=thirdparty%2Flibcgroup.git lscgroup: don't trim "/" The present version of lscgroup trimmed "/" signs from the end of output path. The functionality was necessary because of cg_build_path function add useless "/" characters to the patch. This is fixed by the previous api patch. Moreover other unix commands (du, grep) leave the format of path as it was added in input (with all typed "/" characters). Thus lscgroup should not remove "/" which were added in command line. Example old version: $ lscgroup memory://abc/// memory:/abc/// memory:/abc///gh memory:/abc///def $ lscgroup cpuset:/ cpuset:/3 new version: $ lscgroup memory://abc/// memory://abc/// memory://abc///gh memory://abc///def $ lscgroup cpuset:/ cpuset:/3 Signed-off-by: Ivana Hutarova Varekova Acked-by: Dhaval Giani --- diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index c16f193b..3b74aadb 100644 --- a/src/tools/lscgroup.c +++ b/src/tools/lscgroup.c @@ -87,20 +87,25 @@ static int display_controller_data(char *input_path, char *controller, char *nam int ret; void *handle; struct cgroup_file_info info; + char cgroup_dir_path[FILENAME_MAX]; char input_dir_path[FILENAME_MAX]; int lvl; int len; - 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, + ret = cgroup_walk_tree_begin(controller, input_path, 0, &handle, &info, &lvl); if (ret != 0) return ret; - len = strlen(info.full_path) - strlen(input_dir_path) - 1; + strncpy(cgroup_dir_path, info.full_path, FILENAME_MAX); + /* remove problematic '/' characters from cgroup directory path*/ + trim_filepath(cgroup_dir_path); + + strncpy(input_dir_path, input_path, FILENAME_MAX); + + /* remove problematic '/' characters from input directory path*/ + trim_filepath(input_dir_path); + len = strlen(cgroup_dir_path) - strlen(input_dir_path); print_info(&info, name, len); while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) == 0) print_info(&info, name, len);