]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgconfig.c: fix checkpatch.pl warnings
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 16 Mar 2022 15:22:59 +0000 (20:52 +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, 11 warnings, 213 lines checked

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

index 9c419d3d83f2c961c26fe987e41b61a735527ba9..7d37d5ece93ffa132fd70d54f960bf38aa2e3602 100644 (file)
@@ -3,81 +3,85 @@
  * Copyright IBM Corporation. 2007
  *
  * Authors:    Dhaval Giani <dhaval@linux.vnet.ibm.com>
- *             Balbir Singh <balbir@linux.vnet.ibm.com>
+ *             Balbir Singh <balbir@linux.vnet.ibm.com>
  *
  * Code initiated and designed by Dhaval Giani. All faults are most likely
  * his mistake.
  */
 
-#include <libcgroup.h>
-#include <libcgroup-internal.h>
-
 /* For basename() */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif
+
+#include "tools-common.h"
+
+#include <libcgroup.h>
+#include <libcgroup-internal.h>
+
 #include <string.h>
 #include <libgen.h>
 
-#include <stdio.h>
 #include <stdlib.h>
-#include <errno.h>
 #include <getopt.h>
-#include "tools-common.h"
+#include <stdio.h>
+#include <errno.h>
 
 static struct cgroup_string_list cfg_files;
 
 static void usage(int status, char *progname)
 {
        if (status != 0) {
-               fprintf(stderr, "Wrong input parameters, "\
-                       "try %s -h' for more information.\n", progname);
+               fprintf(stderr, "Wrong input parameters, ");
+               fprintf(stderr, "try %s -h' for more information.\n", progname);
                return;
        }
-       printf("Usage: %s [-h] [-f mode] [-d mode] [-s mode] "\
-               "[-t <tuid>:<tgid>] [-a <agid>:<auid>] [-l FILE] "\
-               "[-L DIR] ...\n", progname);
+       printf("Usage: %s [-h] [-f mode] [-d mode] [-s mode] ", progname);
+       printf("[-t <tuid>:<tgid>] [-a <agid>:<auid>] [-l FILE] ");
+       printf("[-L DIR] ...\n");
        printf("Parse and load the specified cgroups configuration file\n");
-       printf("  -a <tuid>:<tgid>              Default owner of groups files "\
-               "and directories\n");
-       printf("  -d, --dperm=mode              Default group directory "\
-               "permissions\n");
-       printf("  -f, --fperm=mode              Default group file "\
-               "permissions\n");
+       printf("  -a <tuid>:<tgid>              Default owner of groups ");
+       printf("files and directories\n");
+       printf("  -d, --dperm=mode              Default group directory ");
+       printf("permissions\n");
+       printf("  -f, --fperm=mode              Default group file ");
+       printf("permissions\n");
        printf("  -h, --help                    Display this help\n");
-       printf("  -l, --load=FILE               Parse and load the cgroups "\
-               "configuration file\n");
-       printf("  -L, --load-directory=DIR      Parse and load the cgroups "\
-               "configuration files from a directory\n");
-       printf("  -s, --tperm=mode              Default tasks file "\
-               "permissions\n");
-       printf("  -t <tuid>:<tgid>              Default owner of the tasks "\
-               "file\n");
+       printf("  -l, --load=FILE               Parse and load the cgroups ");
+       printf("configuration file\n");
+       printf("  -L, --load-directory=DIR      Parse and load the cgroups ");
+       printf("configuration files from a directory\n");
+       printf("  -s, --tperm=mode              Default tasks file ");
+       printf("permissions\n");
+       printf("  -t <tuid>:<tgid>              Default owner of the tasks ");
+       printf("file\n");
 }
 
 int main(int argc, char *argv[])
 {
-       int c, i;
-       int ret, error = 0;
        static struct option options[] = {
-               {"help", 0, 0, 'h'},
-               {"load", 1, 0, 'l'},
-               {"load-directory", 1, 0, 'L'},
-               {"task", required_argument, NULL, 't'},
-               {"admin", required_argument, NULL, 'a'},
-               {"dperm", required_argument, NULL, 'd'},
-               {"fperm", required_argument, NULL, 'f' },
-               {"tperm", required_argument, NULL, 's' },
+               {"help",                                0,    0, 'h'},
+               {"load",                                1,    0, 'l'},
+               {"load-directory",                      1,    0, 'L'},
+               {"task",                required_argument, NULL, 't'},
+               {"admin",               required_argument, NULL, 'a'},
+               {"dperm",               required_argument, NULL, 'd'},
+               {"fperm",               required_argument, NULL, 'f' },
+               {"tperm",               required_argument, NULL, 's' },
                {0, 0, 0, 0}
        };
+
        uid_t tuid = NO_UID_GID, auid = NO_UID_GID;
        gid_t tgid = NO_UID_GID, agid = NO_UID_GID;
-       mode_t dir_mode = NO_PERMS;
-       mode_t file_mode = NO_PERMS;
        mode_t tasks_mode = NO_PERMS;
-       int dirm_change = 0;
-       int filem_change = 0;
+       mode_t file_mode = NO_PERMS;
+       mode_t dir_mode = NO_PERMS;
+
        struct cgroup *default_group = NULL;
+       int filem_change = 0;
+       int dirm_change = 0;
+       int ret, error = 0;
+       int c, i;
 
        cgroup_set_default_logger(-1);
 
@@ -98,7 +102,7 @@ int main(int argc, char *argv[])
                goto err;
 
        while ((c = getopt_long(argc, argv, "hl:L:t:a:d:f:s:", options,
-                       NULL)) > 0) {
+                               NULL)) > 0) {
                switch (c) {
                case 'h':
                        usage(0, argv[0]);
@@ -107,14 +111,14 @@ int main(int argc, char *argv[])
                case 'l':
                        error = cgroup_string_list_add_item(&cfg_files, optarg);
                        if (error) {
-                               fprintf(stderr, "%s: cannot add file to list,"\
-                                               " out of memory?\n", argv[0]);
+                               fprintf(stderr, "%s: cannot add file ", argv[0]);
+                               fprintf(stderr, "to list, out of memory?\n");
                                goto err;
                        }
                        break;
                case 'L':
                        cgroup_string_list_add_directory(&cfg_files, optarg,
-                                       argv[0]);
+                                                        argv[0]);
                        break;
                case 'a':
                        /* set admin uid/gid */
@@ -170,19 +174,19 @@ int main(int argc, char *argv[])
        error = cgroup_set_uid_gid(default_group, tuid, tgid, auid, agid);
        if (error) {
                fprintf(stderr, "%s: cannot set default UID and GID: %s\n",
-                               argv[0], cgroup_strerror(error));
+                       argv[0], cgroup_strerror(error));
                goto free_cgroup;
        }
 
        if (dirm_change | filem_change) {
                cgroup_set_permissions(default_group, dir_mode, file_mode,
-                               tasks_mode);
+                                      tasks_mode);
        }
 
        error = cgroup_config_set_default(default_group);
        if (error) {
                fprintf(stderr, "%s: cannot set config parser defaults: %s\n",
-                               argv[0], cgroup_strerror(error));
+                       argv[0], cgroup_strerror(error));
                goto free_cgroup;
        }
 
@@ -190,8 +194,7 @@ int main(int argc, char *argv[])
                ret = cgroup_config_load_config(cfg_files.items[i]);
                if (ret) {
                        fprintf(stderr, "%s; error loading %s: %s\n", argv[0],
-                                       cfg_files.items[i],
-                                       cgroup_strerror(ret));
+                               cfg_files.items[i], cgroup_strerror(ret));
                        if (!error)
                                error = ret;
                }
@@ -201,5 +204,6 @@ free_cgroup:
        cgroup_free(&default_group);
 err:
        cgroup_string_list_free(&cfg_files);
+
        return error;
 }