diff options
author | Balbir Singh <balbir@linux.vnet.ibm.com> | 2009-10-09 20:15:34 +0530 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-10-23 00:59:09 +0530 |
commit | 797a53825f0f9c1678f231cd16735e31436513ec (patch) | |
tree | 7fedc731323834f881a9c944947083424b5a8cc2 /src/tools | |
parent | 9c012385dbd80003ba5fe920e644f944ae8eceb3 (diff) | |
download | libcg-797a53825f0f9c1678f231cd16735e31436513ec.tar.gz libcg-797a53825f0f9c1678f231cd16735e31436513ec.tar.xz libcg-797a53825f0f9c1678f231cd16735e31436513ec.zip |
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 <balbir@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/lscgroup.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index 5e3e80b..5164d35 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); |