From: Kamalesh Babulal Date: Tue, 22 Mar 2022 10:04:10 +0000 (+0530) Subject: cgclassify: adopt err()/info() for printing messages X-Git-Tag: v3.0~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84517e875818d9a41870d3f97e3641f293e9800b;p=thirdparty%2Flibcgroup.git cgclassify: adopt err()/info() for printing messages Replace usage of fprintf(stderr, ...) with err() and printf(...) with info(). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c index e2f5e8a5..9f19b830 100644 --- a/src/tools/cgclassify.c +++ b/src/tools/cgclassify.c @@ -29,21 +29,20 @@ static void usage(int status, const char *program_name) { if (status != 0) { - fprintf(stderr, "Wrong input parameters,"); - fprintf(stderr, " try %s -h' for more information.\n", - program_name); + err("Wrong input parameters, "); + err("try %s '-h' for more information.\n", program_name); return; } - printf("Usage: %s [[-g] :] ", program_name); - printf("[--sticky | --cancel-sticky] \n"); - printf("Move running task(s) to given cgroups\n"); - printf(" -h, --help Display this help\n"); - printf(" -g : Control group to be used "); - printf("as target\n"); - printf(" --cancel-sticky cgred daemon change pidlist "); - printf("and children tasks\n"); - printf(" --sticky cgred daemon does not change "); - printf("pidlist and children tasks\n"); + + info("Usage: %s [[-g] :] ", program_name); + info("[--sticky | --cancel-sticky] \n"); + info("Move running task(s) to given cgroups\n"); + info(" -h, --help Display this help\n"); + info(" -g : Control group to be used as target\n"); + info(" --cancel-sticky cgred daemon change pidlist "); + info("and children tasks\n"); + info(" --sticky cgred daemon does not change "); + info("pidlist and children tasks\n"); } /* @@ -61,8 +60,8 @@ static int change_group_path(pid_t pid, struct cgroup_group_spec *cgroup_list[]) ret = cgroup_change_cgroup_path(cgroup_list[i]->path, pid, (const char *const*) cgroup_list[i]->controllers); if (ret) { - fprintf(stderr, "Error changing group of pid %d: %s\n", - pid, cgroup_strerror(ret)); + err("Error changing group of pid %d: %s\n", pid, + cgroup_strerror(ret)); return -1; } } @@ -82,23 +81,21 @@ static int change_group_based_on_rule(pid_t pid) /* Put pid into right cgroup as per rules in /etc/cgrules.conf */ if (cgroup_get_uid_gid_from_procfs(pid, &euid, &egid)) { - fprintf(stderr, "Error in determining euid/egid of "); - fprintf(stderr, "pid %d\n", pid); + err("Error in determining euid/egid of pid %d\n", pid); goto out; } ret = cgroup_get_procname_from_procfs(pid, &procname); if (ret) { - fprintf(stderr, "Error in determining process name of "); - fprintf(stderr, "pid %d\n", pid); + err("Error in determining process name of pid %d\n", pid); goto out; } /* Change the cgroup by determining the rules */ ret = cgroup_change_cgroup_flags(euid, egid, procname, pid, 0); if (ret) { - fprintf(stderr, "Error: change of cgroup failed for "); - fprintf(stderr, "pid %d: %s\n", pid, cgroup_strerror(ret)); + err("Error: change of cgroup failed for pid %d: %s\n", pid, + cgroup_strerror(ret)); goto out; } ret = 0; @@ -143,8 +140,8 @@ int main(int argc, char *argv[]) ret = parse_cgroup_spec(cgroup_list, optarg, CG_HIER_MAX); if (ret) { - fprintf(stderr, "cgroup controller and path "); - fprintf(stderr, "parsing failed\n"); + err("cgroup controller and path parsing "); + err("failed\n"); return -1; } cg_specified = 1; @@ -165,8 +162,8 @@ int main(int argc, char *argv[]) /* Initialize libcg */ ret = cgroup_init(); if (ret) { - fprintf(stderr, "%s: libcgroup initialization failed: %s\n", - argv[0], cgroup_strerror(ret)); + err("%s: libcgroup initialization failed: %s\n", argv[0], + cgroup_strerror(ret)); return ret; } @@ -174,8 +171,7 @@ int main(int argc, char *argv[]) pid = (pid_t) strtol(argv[i], &endptr, 10); if (endptr[0] != '\0') { /* the input argument was not a number */ - fprintf(stderr, "Error: %s is not valid pid.\n", - argv[i]); + err("Error: %s is not valid pid.\n", argv[i]); exit_code = 2; continue; }