]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
lscgroup.c: fix checkpatch.pl warnings
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 16 Mar 2022 15:45:33 +0000 (21:15 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 16 Mar 2022 21:38:20 +0000 (15:38 -0600)
Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl,
except SPDX_LICENSE_TAG, USE_NEGATIVE_ERRNO and NEW_TYPEDEFS types.  It
also introduces reverse xmas tree local variable declarations and header
file reordering.

In summary, this patch fixes the following checkpatch.pl
recommendations:
total: 0 errors, 9 warnings, 328 lines checked

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

index 840fb604e827398d8e3a253b9827cf2987989a73..209935cbfd2e07e36c7939e5efafdd4d4172c465 100644 (file)
@@ -4,17 +4,18 @@
  * Written by Ivana Hutarova Varekova <varekova@redhat.com>
  */
 
-#include <stdio.h>
+#include "tools-common.h"
+
+#include <libcgroup.h>
+#include <libcgroup-internal.h>
+
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
+#include <stdio.h>
 
-#include <libcgroup.h>
-#include <libcgroup-internal.h>
-#include "tools-common.h"
-
-enum flag{
+enum flag {
        /*
         * the flag set if there is a cgroup on output
         * if there is no one we want to display all cgroups
@@ -25,6 +26,7 @@ enum flag{
 static inline void trim_filepath(char *path)
 {
        int len;
+
        len = strlen(path) - 1;
        while (path[len] == '/')
                len--;
@@ -35,16 +37,16 @@ static inline void trim_filepath(char *path)
 static void usage(int status, const char *program_name)
 {
        if (status != 0) {
-               fprintf(stderr, "Wrong input parameters,"
-                       " try %s -h' for more information.\n",
+               fprintf(stderr, "Wrong input parameters,");
+               fprintf(stderr, " try %s -h' for more information.\n",
                        program_name);
                return;
        }
        printf("Usage: %s [-h] [[-g] <controllers>:<path>] [...]\n",
                program_name);
        printf("List all cgroups\n");
-       printf("  -g <controllers>:<path>       Control group to be displayed "\
-               "(-g is optional)\n");
+       printf("  -g <controllers>:<path>       Control group to be ");
+       printf("displayed (-g is optional)\n");
        printf("  -h, --help                    Display this help\n");
 }
 
@@ -77,31 +79,30 @@ static void print_info(struct cgroup_file_info *info, char *name, int pref)
 /* display controller:/input_path cgroups */
 static int display_controller_data(char *input_path, char *controller, char *name)
 {
-       int ret;
-       void *handle;
-       struct cgroup_file_info info;
        char cgroup_dir_path[FILENAME_MAX];
        char input_dir_path[FILENAME_MAX];
-       int lvl;
-       int len;
+       struct cgroup_file_info info;
+       int lvl, len, ret;
+       void *handle;
 
        ret = cgroup_walk_tree_begin(controller, input_path, 0,
-               &handle, &info, &lvl);
+                                    &handle, &info, &lvl);
        if (ret != 0)
                return ret;
 
        strncpy(cgroup_dir_path, info.full_path, FILENAME_MAX);
        cgroup_dir_path[sizeof(cgroup_dir_path) - 1] = '\0';
-       /* remove problematic  '/' characters from cgroup directory path*/
+       /* remove problematic  '/' characters from cgroup directory path */
        trim_filepath(cgroup_dir_path);
 
        strncpy(input_dir_path, input_path, FILENAME_MAX);
        input_dir_path[sizeof(input_dir_path) - 1] = '\0';
 
-       /* remove problematic  '/' characters from input directory path*/
+       /* remove problematic  '/' characters from input directory path */
        trim_filepath(input_dir_path);
        len  = strlen(cgroup_dir_path) - strlen(input_dir_path);
        print_info(&info, name, len);
+
        while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) == 0)
                print_info(&info, name, len);
 
@@ -120,13 +121,13 @@ static int display_controller_data(char *input_path, char *controller, char *nam
 
 static int print_cgroup(struct cgroup_group_spec *cgroup_spec, int flags)
 {
-       int ret = 0;
-       void *handle;
        struct cgroup_mount_point controller;
-       char path[FILENAME_MAX];
-       char con_name[FILENAME_MAX];
        char all_conts[FILENAME_MAX];
+       char con_name[FILENAME_MAX];
+       char path[FILENAME_MAX];
        int output = 0;
+       void *handle;
+       int ret = 0;
 
        path[0] = '\0';
        con_name[0] = '\0';
@@ -147,8 +148,8 @@ static int print_cgroup(struct cgroup_group_spec *cgroup_spec, int flags)
                        /* we got new mount point, print it if needed */
                        if (output) {
                                ret = display_controller_data(
-                                       cgroup_spec->path,
-                                       con_name, all_conts);
+                                                       cgroup_spec->path,
+                                                       con_name, all_conts);
                                if (ret)
                                        return ret;
                                if ((flags & FL_LIST) != 0) {
@@ -161,15 +162,17 @@ static int print_cgroup(struct cgroup_group_spec *cgroup_spec, int flags)
                        output = 0;
                        strncpy(all_conts, controller.name, FILENAME_MAX);
                        all_conts[FILENAME_MAX-1] = '\0';
+
                        strncpy(con_name, controller.name, FILENAME_MAX);
                        con_name[FILENAME_MAX-1] = '\0';
+
                        strncpy(path, controller.path, FILENAME_MAX);
                        path[FILENAME_MAX-1] = '\0';
                }
 
                /* set output flag */
                if ((output == 0) && (!(flags & FL_LIST) ||
-                       (is_ctlr_on_list(cgroup_spec, controller.name))))
+                   (is_ctlr_on_list(cgroup_spec, controller.name))))
                        output = 1;
 
                /* the actual controller should not be printed */
@@ -181,9 +184,8 @@ static int print_cgroup(struct cgroup_group_spec *cgroup_spec, int flags)
                return ret;
 
        if (output) {
-               ret = display_controller_data(
-                       cgroup_spec->path,
-                       con_name, all_conts);
+               ret = display_controller_data(cgroup_spec->path,
+                                             con_name, all_conts);
        }
 
        return ret;
@@ -191,11 +193,11 @@ static int print_cgroup(struct cgroup_group_spec *cgroup_spec, int flags)
 
 
 static int cgroup_list_cgroups(char *tname,
-       struct cgroup_group_spec *cgroup_list[],
-       int flags)
+                              struct cgroup_group_spec *cgroup_list[],
+                              int flags)
 {
-       int ret = 0;
        int final_ret = 0;
+       int ret = 0;
        int i = 0;
 
        /* initialize libcgroup */
@@ -208,6 +210,7 @@ static int cgroup_list_cgroups(char *tname,
 
        if ((flags & FL_LIST) == 0) {
                struct cgroup_group_spec *cgroup_spec;
+
                cgroup_spec = calloc(1, sizeof(struct cgroup_group_spec));
                /* we have to print all cgroups */
                ret = print_cgroup(cgroup_spec,  flags);
@@ -223,6 +226,7 @@ static int cgroup_list_cgroups(char *tname,
                /* we have he list of controllers which should be print */
                while ((cgroup_list[i] != NULL)
                        && ((ret == ECGEOF) || (ret == 0))) {
+
                        ret = print_cgroup(cgroup_list[i], flags);
                        if (ret != 0) {
                                if (ret == ECGEOF) {
@@ -241,26 +245,24 @@ static int cgroup_list_cgroups(char *tname,
                        i++;
                }
        }
+
        return final_ret;
 }
 
 int main(int argc, char *argv[])
 {
-
-       int ret = 0;
-       int c;
-       int i;
-
-       int flags = 0;
-
-       struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
-
        static struct option options[] = {
                {"help", 0, 0, 'h'},
                {"group", required_argument, NULL, 'g'},
                {0, 0, 0, 0}
        };
 
+       struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
+       int flags = 0;
+       int ret = 0;
+       int c;
+       int i;
+
        memset(cgroup_list, 0, sizeof(cgroup_list));
 
        /* parse arguments */
@@ -274,9 +276,10 @@ int main(int argc, char *argv[])
                        ret = parse_cgroup_spec(cgroup_list, optarg,
                                CG_HIER_MAX);
                        if (ret) {
-                               fprintf(stderr, "%s: cgroup controller"
-                                       " and path parsing failed (%s)\n",
-                                       argv[0], optarg);
+                               fprintf(stderr, "%s: cgroup controller and ",
+                                       argv[0]);
+                               fprintf(stderr, "path parsing failed (%s)\n",
+                                       optarg);
                                return ret;
                        }
                        break;
@@ -292,9 +295,9 @@ int main(int argc, char *argv[])
                ret = parse_cgroup_spec(cgroup_list, argv[optind],
                                CG_HIER_MAX);
                if (ret) {
-                       fprintf(stderr, "%s: cgroup controller"
-                               " and path parsing failed (%s)\n",
-                               argv[0], argv[optind]);
+                       fprintf(stderr, "%s: cgroup controller", argv[0]);
+                       fprintf(stderr, " and path parsing failed (%s)\n",
+                               argv[optind]);
                        return -1;
                }
                optind++;
@@ -305,8 +308,7 @@ int main(int argc, char *argv[])
                flags |= FL_LIST;
        }
 
-       /* print the information
-          based on list of input cgroups and flags */
+       /* print the information based on list of input cgroups and flags */
        ret = cgroup_list_cgroups(argv[0], cgroup_list, flags);
 
 err:
@@ -317,6 +319,5 @@ err:
                }
        }
 
-
        return ret;
 }