]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgget: fix '-m' option usage
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Sun, 16 Apr 2023 04:40:13 +0000 (10:10 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 17 Apr 2023 17:56:26 +0000 (11:56 -0600)
'-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 ce809ea7519b2741edbb823618fdf6796de1f4d0)

src/tools/cgget.c

index b35d35450313729484cd03709af7433383958e82..4447ecfe551c21a3ace7c8149e12178e5cbf4bc2 100644 (file)
@@ -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;