From: Kamalesh Babulal Date: Wed, 16 Mar 2022 15:22:59 +0000 (+0530) Subject: cgconfig.c: fix checkpatch.pl warnings X-Git-Tag: v3.0~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5caaae47de0bd0ba6b10fbdb9196f75ea9f1bfe8;p=thirdparty%2Flibcgroup.git cgconfig.c: fix checkpatch.pl warnings 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 Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgconfig.c b/src/tools/cgconfig.c index 9c419d3d..7d37d5ec 100644 --- a/src/tools/cgconfig.c +++ b/src/tools/cgconfig.c @@ -3,81 +3,85 @@ * Copyright IBM Corporation. 2007 * * Authors: Dhaval Giani - * Balbir Singh + * Balbir Singh * * Code initiated and designed by Dhaval Giani. All faults are most likely * his mistake. */ -#include -#include - /* For basename() */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif + +#include "tools-common.h" + +#include +#include + #include #include -#include #include -#include #include -#include "tools-common.h" +#include +#include 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 :] [-a :] [-l FILE] "\ - "[-L DIR] ...\n", progname); + printf("Usage: %s [-h] [-f mode] [-d mode] [-s mode] ", progname); + printf("[-t :] [-a :] [-l FILE] "); + printf("[-L DIR] ...\n"); printf("Parse and load the specified cgroups configuration file\n"); - printf(" -a : 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 : 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 : 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 : 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; }