]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgget: increase the column width to 100
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 30 Jun 2022 14:14:25 +0000 (19:44 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 11 Jul 2022 19:19:54 +0000 (13:19 -0600)
100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgget.c

index b7619cf5de274714062db0d4856edf8fd34c190b..5c3d302020b4941c4354d9f2f7f14f701fe64b46 100644 (file)
 #include <unistd.h>
 #include <stdio.h>
 
-#define MODE_SHOW_HEADERS              1
-#define MODE_SHOW_NAMES                        2
+#define MODE_SHOW_HEADERS      1
+#define MODE_SHOW_NAMES                2
 
-#define LL_MAX                         100
+#define LL_MAX                 100
 
 static const struct option long_options[] = {
        {"variable",    required_argument, NULL, 'r'},
@@ -28,21 +28,14 @@ static const struct option long_options[] = {
 static void usage(int status, const char *program_name)
 {
        if (status != 0) {
-               err("Wrong input parameters,");
-               err(" try %s -h' for more information.\n", program_name);
+               err("Wrong input parameters, try %s -h' for more information.\n", program_name);
                return;
        }
-       info("Usage: %s [-nv] [-r <name>] [-g <controllers>] ", program_name);
-       info("[-a] <path> ...\n");
-       info("   or: %s [-nv] [-r <name>] -g <controllers>:<path> ...\n",
-            program_name);
+       info("Usage: %s [-nv] [-r <name>] [-g <controllers>] [-a] <path> ...\n", program_name);
        info("Print parameter(s) of given group(s).\n");
-       info("  -a, --all                       Print info about all relevant ");
-       info("controllers\n");
-       info("  -g <controllers>                Controller which info should ");
-       info("be displayed\n");
-       info("  -g <controllers>:<path> Control group which info ");
-       info("should be displayed\n");
+       info("  -a, --all                       Print info about all relevant controllers\n");
+       info("  -g <controllers>                Controller which info should be displayed\n");
+       info("  -g <controllers>:<path> Control group which info should be displayed\n");
        info("  -h, --help                      Display this help\n");
        info("  -n                              Do not print headers\n");
        info("  -r, --variable <name>           Define parameter to display\n");
@@ -50,8 +43,7 @@ static void usage(int status, const char *program_name)
        info("parameter names\n");
 }
 
-static int get_controller_from_name(const char * const name,
-                                   char **controller)
+static int get_controller_from_name(const char * const name, char **controller)
 {
        char *dot;
 
@@ -61,19 +53,17 @@ static int get_controller_from_name(const char * const name,
 
        dot = strchr(*controller, '.');
        if (dot == NULL) {
-               err("cgget: error parsing parameter name\n");
-               err(    " '%s'", name);
+               err("cgget: error parsing parameter name '%s'", name);
                return ECGINVAL;
        }
-
        *dot = '\0';
+
        return 0;
 }
 
 static int create_cg(struct cgroup **cg_list[], int * const cg_list_len)
 {
-       *cg_list = realloc(*cg_list,
-                          ((*cg_list_len) + 1) * sizeof(struct cgroup *));
+       *cg_list = realloc(*cg_list, ((*cg_list_len) + 1) * sizeof(struct cgroup *));
        if ((*cg_list) == NULL)
                return ECGCONTROLLERCREATEFAILED;
 
@@ -84,6 +74,7 @@ static int create_cg(struct cgroup **cg_list[], int * const cg_list_len)
                return ECGCONTROLLERCREATEFAILED;
 
        (*cg_list_len)++;
+
        return 0;
 }
 
@@ -102,9 +93,9 @@ static int parse_a_flag(struct cgroup **cg_list[], int * const cg_list_len)
        }
 
        /*
-        * if "-r" was provided, then we know that the cgroup(s) will be an
-        * optarg at the end with no flag.  Let's temporarily populate the
-        * first cgroup with the requested control values.
+        * if "-r" was provided, then we know that the cgroup(s) will be
+        * an optarg at the end with no flag.  Let's temporarily populate
+        * the first cgroup with the requested control values.
         */
        cg = (*cg_list)[0];
 
@@ -114,13 +105,11 @@ static int parse_a_flag(struct cgroup **cg_list[], int * const cg_list_len)
                if (!cgc) {
                        cgc = cgroup_add_controller(cg, controller.name);
                        if (!cgc) {
-                               err("cgget: cannot find controller '%s'\n",
-                                   controller.name);
+                               err("cgget: cannot find controller '%s'\n", controller.name);
                                ret = ECGOTHER;
                                goto out;
                        }
                }
-
                ret = cgroup_get_controller_next(&handle, &controller);
        }
        if (ret == ECGEOF)
@@ -133,8 +122,10 @@ static int parse_a_flag(struct cgroup **cg_list[], int * const cg_list_len)
        cgroup_get_controller_end(&handle);
 
        return ret;
+
 out:
        cgroup_get_controller_end(&handle);
+
        return ret;
 }
 
@@ -153,9 +144,9 @@ static int parse_r_flag(struct cgroup **cg_list[], int * const cg_list_len,
        }
 
        /*
-        * if "-r" was provided, then we know that the cgroup(s) will be an
-        * optarg at the end with no flag.  Let's temporarily populate the
-        * first cgroup with the requested control values.
+        * if "-r" was provided, then we know that the cgroup(s) will be
+        * an optarg at the end with no flag.  Let's temporarily populate
+        * the first cgroup with the requested control values.
         */
        cg = (*cg_list)[0];
 
@@ -167,8 +158,7 @@ static int parse_r_flag(struct cgroup **cg_list[], int * const cg_list_len,
        if (!cgc) {
                cgc = cgroup_add_controller(cg, cntl_value_controller);
                if (!cgc) {
-                       err("cgget: cannot find controller '%s'\n",
-                           cntl_value_controller);
+                       err("cgget: cannot find controller '%s'\n", cntl_value_controller);
                        ret = ECGOTHER;
                        goto out;
                }
@@ -179,11 +169,11 @@ static int parse_r_flag(struct cgroup **cg_list[], int * const cg_list_len,
 out:
        if (cntl_value_controller)
                free(cntl_value_controller);
+
        return ret;
 }
 
-static int parse_g_flag_no_colon(struct cgroup **cg_list[],
-                                int * const cg_list_len,
+static int parse_g_flag_no_colon(struct cgroup **cg_list[], int * const cg_list_len,
                                 const char * const ctrl_str)
 {
        struct cgroup_controller *cgc;
@@ -238,8 +228,7 @@ static int split_cgroup_name(const char * const ctrl_str, char *cg_name)
        return 0;
 }
 
-static int split_controllers(const char * const in,
-                            char **ctrl[], int * const ctrl_len)
+static int split_controllers(const char * const in, char **ctrl[], int * const ctrl_len)
 {
        char *copy, *tok, *colon, *saveptr = NULL;
        int ret = 0;
@@ -274,11 +263,11 @@ static int split_controllers(const char * const in,
 out:
        if (saveptr)
                free(saveptr);
+
        return ret;
 }
 
-static int parse_g_flag_with_colon(struct cgroup **cg_list[],
-                                  int * const cg_list_len,
+static int parse_g_flag_with_colon(struct cgroup **cg_list[], int * const cg_list_len,
                                   const char * const ctrl_str)
 {
        struct cgroup_controller *cgc;
@@ -306,8 +295,7 @@ static int parse_g_flag_with_colon(struct cgroup **cg_list[],
                if (!cgc) {
                        cgc = cgroup_add_controller(cg, controllers[i]);
                        if (!cgc) {
-                               err("cgget: cannot find controller '%s'\n",
-                                   controllers[i]);
+                               err("cgget: cannot find controller '%s'\n", controllers[i]);
                                ret = ECGOTHER;
                                goto out;
                        }
@@ -317,6 +305,7 @@ static int parse_g_flag_with_colon(struct cgroup **cg_list[],
 out:
        for (i = 0; i < controllers_len; i++)
                free(controllers[i]);
+
        return ret;
 }
 
@@ -327,8 +316,8 @@ static int parse_opt_args(int argc, char *argv[], struct cgroup **cg_list[],
        int ret = 0;
 
        /*
-        * The first cgroup was temporarily populated and requires
-        * the user to provide a cgroup name as an opt
+        * The first cgroup was temporarily populated and requires the
+        * user to provide a cgroup name as an opt
         */
        if (argv[optind] == NULL && first_cg_is_dummy) {
                usage(1, argv[0]);
@@ -337,8 +326,8 @@ static int parse_opt_args(int argc, char *argv[], struct cgroup **cg_list[],
 
        /*
         * The user has provided a cgroup and controller via the
-        * -g <controller>:<cgroup> flag and has also provided a cgroup via
-        * the optind.  This was not supported by the previous cgget
+        * -g <controller>:<cgroup> flag and has also provided a cgroup
+        *  via the optind.  This was not supported by the previous cgget
         * implementation.  Continue that approach.
         *
         * Example of a command that will hit this code:
@@ -367,15 +356,13 @@ static int parse_opt_args(int argc, char *argv[], struct cgroup **cg_list[],
                        if (ret)
                                goto out;
 
-                       strncpy((*cg_list)[(*cg_list_len) - 1]->name,
-                               argv[optind],
+                       strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
                                sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
                } else if (cg != NULL && strlen(cg->name) == 0) {
                        /*
                         * this cgroup was created based upon control/value
                         * pairs or with a -g <controller> option.  we'll
-                        * populate it with the parameter provided by the
-                        * user
+                        * populate it with the parameter provided by the user
                         */
                        strncpy(cg->name, argv[optind], sizeof(cg->name) - 1);
                } else {
@@ -388,11 +375,9 @@ static int parse_opt_args(int argc, char *argv[], struct cgroup **cg_list[],
                        if (ret)
                                goto out;
 
-                       strncpy((*cg_list)[(*cg_list_len) - 1]->name,
-                               argv[optind],
+                       strncpy((*cg_list)[(*cg_list_len) - 1]->name, argv[optind],
                                sizeof((*cg_list)[(*cg_list_len) - 1]->name) - 1);
                }
-
                optind++;
        }
 
@@ -400,8 +385,8 @@ out:
        return ret;
 }
 
-static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[],
-                     int * const cg_list_len, int * const mode)
+static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[], int * const cg_list_len,
+                     int * const mode)
 {
        bool do_not_fill_controller = false;
        bool first_cgroup_is_dummy = false;
@@ -410,8 +395,7 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[],
        int c;
 
        /* Parse arguments. */
-       while ((c = getopt_long(argc, argv, "r:hnvg:a", long_options,
-                               NULL)) > 0) {
+       while ((c = getopt_long(argc, argv, "r:hnvg:a", long_options, NULL)) > 0) {
                switch (c) {
                case 'h':
                        usage(0, argv[0]);
@@ -435,13 +419,11 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[],
                        fill_controller = true;
                        if (strchr(optarg, ':') == NULL) {
                                first_cgroup_is_dummy = true;
-                               ret = parse_g_flag_no_colon(cg_list,
-                                       cg_list_len, optarg);
+                               ret = parse_g_flag_no_colon(cg_list, cg_list_len, optarg);
                                if (ret)
                                        goto err;
                        } else {
-                               ret = parse_g_flag_with_colon(cg_list,
-                                       cg_list_len, optarg);
+                               ret = parse_g_flag_with_colon(cg_list, cg_list_len, optarg);
                                if (ret)
                                        goto err;
                        }
@@ -464,8 +446,7 @@ static int parse_opts(int argc, char *argv[], struct cgroup **cg_list[],
                exit(1);
        }
 
-       ret = parse_opt_args(argc, argv, cg_list, cg_list_len,
-                            first_cgroup_is_dummy);
+       ret = parse_opt_args(argc, argv, cg_list, cg_list_len, first_cgroup_is_dummy);
        if (ret)
                goto err;
 
@@ -473,8 +454,7 @@ err:
        return ret;
 }
 
-static int get_cv_value(struct control_value * const cv,
-                       const char * const cg_name,
+static int get_cv_value(struct control_value * const cv, const char * const cg_name,
                        const char * const controller_name)
 {
        bool is_multiline = false;
@@ -482,8 +462,8 @@ static int get_cv_value(struct control_value * const cv,
        void *handle, *tmp;
        int ret;
 
-       ret = cgroup_read_value_begin(controller_name, cg_name, cv->name,
-                                     &handle, tmp_line, LL_MAX);
+       ret = cgroup_read_value_begin(controller_name, cg_name, cv->name, &handle, tmp_line,
+                                     LL_MAX);
        if (ret == ECGEOF)
                goto read_end;
        if (ret != 0) {
@@ -497,12 +477,10 @@ static int get_cv_value(struct control_value * const cv,
                         */
                        tmp_ret = cgroup_test_subsys_mounted(controller_name);
                        if (tmp_ret == 0) {
-                               err("cgget: cannot find controller '%s' ",
-                                   controller_name);
-                               err("in group '%s'\n", cg_name);
+                               err("cgget: cannot find controller '%s' in group '%s'\n",
+                                   controller_name, cg_name);
                        } else {
-                               err("variable file read failed %s\n",
-                                   cgroup_strerror(ret));
+                               err("variable file read failed %s\n", cgroup_strerror(ret));
                        }
                }
 
@@ -540,7 +518,6 @@ read_end:
        cgroup_read_value_end(&handle);
        if (ret == ECGEOF)
                ret = 0;
-
 end:
        if (is_multiline == false && cv->multiline_value) {
                free(cv->multiline_value);
@@ -573,8 +550,7 @@ static int indent_multiline_value(struct control_value * const cv)
        return 0;
 }
 
-static int fill_empty_controller(struct cgroup * const cg,
-                                struct cgroup_controller * const cgc)
+static int fill_empty_controller(struct cgroup * const cg, struct cgroup_controller * const cgc)
 {
        struct dirent *ctrl_dir = NULL;
        bool found_mount = false;
@@ -584,11 +560,9 @@ static int fill_empty_controller(struct cgroup * const cg,
 
        pthread_rwlock_rdlock(&cg_mount_table_lock);
 
-       for (i = 0; i < CG_CONTROLLER_MAX && cg_mount_table[i].name[0] != '\0';
-            i++) {
+       for (i = 0; i < CG_CONTROLLER_MAX && cg_mount_table[i].name[0] != '\0'; i++) {
                if (strlen(cgc->name) == strlen(cg_mount_table[i].name) &&
-                   strncmp(cgc->name, cg_mount_table[i].name,
-                           strlen(cgc->name)) == 0) {
+                   strncmp(cgc->name, cg_mount_table[i].name, strlen(cgc->name)) == 0) {
                        found_mount = true;
                        break;
                }
@@ -597,10 +571,8 @@ static int fill_empty_controller(struct cgroup * const cg,
        if (found_mount == false)
                goto out;
 
-       if (!cg_build_path_locked(NULL, path,
-                                 cg_mount_table[i].name)) {
+       if (!cg_build_path_locked(NULL, path, cg_mount_table[i].name))
                goto out;
-       }
 
        path_len = strlen(path);
        strncat(path, cg->name, FILENAME_MAX - path_len - 1);
@@ -609,8 +581,7 @@ static int fill_empty_controller(struct cgroup * const cg,
        if (access(path, F_OK))
                goto out;
 
-       if (!cg_build_path_locked(cg->name, path,
-               cg_mount_table[i].name))
+       if (!cg_build_path_locked(cg->name, path, cg_mount_table[i].name))
                goto out;
 
        dir = opendir(path);
@@ -632,8 +603,8 @@ static int fill_empty_controller(struct cgroup * const cg,
                        cgc->values[cgc->index - 1]->dirty = false;
 
                        /*
-                        * previous versions of cgget indented the second and
-                        * all subsequent lines.  continue that behavior
+                        * previous versions of cgget indented the second
+                        * and all subsequent lines. Continue that behavior
                         */
                        if (strchr(cgc->values[cgc->index - 1]->value, '\n')) {
                                ret = indent_multiline_value(
@@ -649,11 +620,11 @@ out:
                closedir(dir);
 
        pthread_rwlock_unlock(&cg_mount_table_lock);
+
        return ret;
 }
 
-static int get_controller_values(struct cgroup * const cg,
-                                struct cgroup_controller * const cgc)
+static int get_controller_values(struct cgroup * const cg, struct cgroup_controller * const cgc)
 {
        int ret = 0;
        int i;
@@ -759,8 +730,7 @@ int main(int argc, char *argv[])
 
        ret = cgroup_init();
        if (ret) {
-               err("%s: libcgroup initialization failed: %s\n", argv[0],
-                   cgroup_strerror(ret));
+               err("%s: libcgroup initialization failed: %s\n", argv[0], cgroup_strerror(ret));
                goto err;
        }