Skip to content

Commit

Permalink
tools/cgget: fix '-m' option usage
Browse files Browse the repository at this point in the history
'-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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ce809ea)
  • Loading branch information
kamalesh-babulal authored and drakenclimber committed Apr 17, 2023
1 parent 7d69a27 commit e73a3e3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/tools/cgget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand All @@ -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;
Expand Down

0 comments on commit e73a3e3

Please sign in to comment.