From: Kamalesh Babulal Date: Sun, 16 Apr 2023 04:40:13 +0000 (+0530) Subject: tools/cgget: fix '-m' option usage X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e73a3e34db7f4988b9828ca78d666aa230326e65;p=thirdparty%2Flibcgroup.git tools/cgget: fix '-m' option usage '-m' is logically an independent option and should not be mixed and matched with other options and also when used with '-h', help always takes precedence over other options. Fix both cases of usage with a bool flag, that gets set when parsing the command line option but executes only it meets the rules of not mixing with other options. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit ce809ea7519b2741edbb823618fdf6796de1f4d0) --- diff --git a/src/tools/cgget.c b/src/tools/cgget.c index b35d3545..4447ecfe 100644 --- a/src/tools/cgget.c +++ b/src/tools/cgget.c @@ -398,6 +398,7 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * c { bool do_not_fill_controller = false; bool first_cgroup_is_dummy = false; + bool cgroup_mount_type = false; bool fill_controller = false; int ret = 0; int c; @@ -451,9 +452,7 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * c goto err; break; case 'm': - ret = find_cgroup_mount_type(); - if (ret) - goto err; + cgroup_mount_type = true; break; default: usage(1, argv[0]); @@ -467,6 +466,18 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * c exit(EXIT_BADARGS); } + /* '-m' should not used with other options */ + if (cgroup_mount_type && (fill_controller || do_not_fill_controller)) { + usage(1, argv[0]); + exit(EXIT_BADARGS); + } + + if (cgroup_mount_type) { + ret = find_cgroup_mount_type(); + if (ret) + goto err; + } + ret = parse_opt_args(argc, argv, cg_list, cg_list_len, first_cgroup_is_dummy); if (ret) goto err;