]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Minor improvements and refactoring of lscgroups
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Fri, 9 Oct 2009 14:45:34 +0000 (20:15 +0530)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Thu, 22 Oct 2009 19:29:09 +0000 (00:59 +0530)
This patch removes the excess "/"'s and makes the output
more readable. Please test on your systems as well.

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
src/tools/lscgroup.c

index 5e3e80b3a3b8ca7c1123a40bff14bead4aa01ea2..5164d353ce10d869ff29284429f8116ceaf0b2a1 100644 (file)
@@ -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);