From 797a53825f0f9c1678f231cd16735e31436513ec Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Fri, 9 Oct 2009 20:15:34 +0530 Subject: [PATCH] Minor improvements and refactoring of lscgroups This patch removes the excess "/"'s and makes the output more readable. Please test on your systems as well. Signed-off-by: Balbir Singh Signed-off-by: Dhaval Giani --- src/tools/lscgroup.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index 5e3e80b3..5164d353 100644 --- a/src/tools/lscgroup.c +++ b/src/tools/lscgroup.c @@ -28,6 +28,16 @@ enum flag{ FL_LIST = 1 }; +static inline void trim_filepath(char *path) +{ + int len; + len = strlen(path) - 1; + while (path[len] == '/') + len--; + + path[len + 1] = '\0'; +} + void usage(int status, char *program_name) { if (status != 0) { @@ -86,22 +96,13 @@ int display_controller_data(char *input_path, char *controller, char *name) strncpy(cgroup_dir_path, info.full_path, FILENAME_MAX); /* remove problematic '/' characters from cgroup directory path*/ - len = strlen(cgroup_dir_path)-1; - while (cgroup_dir_path[len] == '/') - len--; - - cgroup_dir_path[len+1] = '\0'; + trim_filepath(cgroup_dir_path); strncpy(input_dir_path, input_path, FILENAME_MAX); /* remove problematic '/' characters from input path*/ - len = strlen(input_dir_path)-1; - while (input_dir_path[len] == '/') - len--; - - input_dir_path[len+1] = '\0'; - - len = strlen(cgroup_dir_path) - strlen(input_dir_path); + trim_filepath(cgroup_dir_path); + len = strlen(cgroup_dir_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); -- 2.47.2