From: Kamalesh Babulal Date: Tue, 22 Mar 2022 10:04:25 +0000 (+0530) Subject: cgset.c: adopt err()/info() for printing messages X-Git-Tag: v3.0~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=687bd819161424ce2d40eb276eb1c624b1d5c343;p=thirdparty%2Flibcgroup.git cgset.c: 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/cgset.c b/src/tools/cgset.c index 76963809..999d4045 100644 --- a/src/tools/cgset.c +++ b/src/tools/cgset.c @@ -35,16 +35,15 @@ static struct cgroup *copy_name_value_from_cgroup(char src_cg_path[FILENAME_MAX] /* create source cgroup */ src_cgroup = cgroup_new_cgroup(src_cg_path); if (!src_cgroup) { - fprintf(stderr, "can't create cgroup: %s\n", - cgroup_strerror(ECGFAIL)); + err("can't create cgroup: %s\n", cgroup_strerror(ECGFAIL)); goto scgroup_err; } /* copy the name-version values to the cgroup structure */ ret = cgroup_get_cgroup(src_cgroup); if (ret != 0) { - fprintf(stderr, "cgroup %s error: %s\n", - src_cg_path, cgroup_strerror(ret)); + err("cgroup %s error: %s\n", src_cg_path, + cgroup_strerror(ret)); goto scgroup_err; } @@ -59,21 +58,19 @@ scgroup_err: static void usage(int status, const char *program_name) { if (status != 0) { - fprintf(stderr, "Wrong input parameters,"); - fprintf(stderr, " try %s --help' for more information.\n", - program_name); + err("Wrong input parameters, "); + err("try %s --help' for more information.\n", program_name); return; } - printf("Usage: %s [-r ] ...\n", - program_name); - printf(" or: %s --copy-from ", program_name); - printf(" ...\n"); - printf("Set the parameters of given cgroup(s)\n"); - printf(" -r, --variable Define parameter "); - printf("to set\n"); - printf(" --copy-from Control group whose "); - printf("parameters will be copied\n"); + info("Usage: %s [-r ] ...\n", program_name); + info(" or: %s --copy-from ", program_name); + info(" ...\n"); + info("Set the parameters of given cgroup(s)\n"); + info(" -r, --variable Define parameter "); + info("to set\n"); + info(" --copy-from Control group whose "); + info("parameters will be copied\n"); } #endif /* !UNIT_TEST */ @@ -86,7 +83,7 @@ STATIC int parse_r_flag(const char * const program_name, copy = strdup(name_value_str); if (copy == NULL) { - fprintf(stderr, "%s: not enough memory\n", program_name); + err("%s: not enough memory\n", program_name); ret = -1; goto err; } @@ -94,8 +91,8 @@ STATIC int parse_r_flag(const char * const program_name, /* parse optarg value */ buf = strtok(copy, "="); if (buf == NULL) { - fprintf(stderr, "%s: wrong parameter of option -r: %s\n", - program_name, optarg); + err("%s: wrong parameter of option -r: %s\n", program_name, + optarg); ret = -1; goto err; } @@ -111,8 +108,8 @@ STATIC int parse_r_flag(const char * const program_name, buf++; if (strlen(buf) == 0) { - fprintf(stderr, "%s: wrong parameter of option -r: %s\n", - program_name, optarg); + err("%s: wrong parameter of option -r: %s\n", program_name, + optarg); ret = -1; goto err; } @@ -143,8 +140,8 @@ int main(int argc, char *argv[]) /* no parameter on input */ if (argc < 2) { - fprintf(stderr, "Usage is %s -r ", argv[0]); - fprintf(stderr, "\n"); + err("Usage is %s -r ", argv[0]); + err("\n"); return -1; } @@ -175,8 +172,7 @@ int main(int argc, char *argv[]) realloc(name_value, nv_max * sizeof(struct control_value)); if (!name_value) { - fprintf(stderr, "%s: ", argv[0]); - fprintf(stderr, "not enough memory\n"); + err("%s: not enough memory\n", argv[0]); ret = -1; goto err; } @@ -208,13 +204,13 @@ int main(int argc, char *argv[]) /* no cgroup name */ if (!argv[optind]) { - fprintf(stderr, "%s: no cgroup specified\n", argv[0]); + err("%s: no cgroup specified\n", argv[0]); ret = -1; goto err; } if (flags == 0) { - fprintf(stderr, "%s: no name-value pair was set\n", argv[0]); + err("%s: no name-value pair was set\n", argv[0]); ret = -1; goto err; } @@ -222,8 +218,8 @@ int main(int argc, char *argv[]) /* initialize libcgroup */ 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)); goto err; } @@ -247,24 +243,24 @@ int main(int argc, char *argv[]) cgroup = cgroup_new_cgroup(argv[optind]); if (!cgroup) { ret = ECGFAIL; - fprintf(stderr, "%s: can't add new cgroup: %s\n", - argv[0], cgroup_strerror(ret)); + err("%s: can't add new cgroup: %s\n", argv[0], + cgroup_strerror(ret)); goto cgroup_free_err; } /* copy the values from the source cgroup to new one */ ret = cgroup_copy_cgroup(cgroup, src_cgroup); if (ret != 0) { - fprintf(stderr, "%s: cgroup %s error: %s\n", - argv[0], src_cg_path, cgroup_strerror(ret)); + err("%s: cgroup %s error: %s\n", argv[0], src_cg_path, + cgroup_strerror(ret)); goto cgroup_free_err; } /* modify cgroup based on values of the new one */ ret = cgroup_modify_cgroup(cgroup); if (ret) { - fprintf(stderr, "%s: cgroup modify error: %s\n", - argv[0], cgroup_strerror(ret)); + err("%s: cgroup modify error: %s\n", argv[0], + cgroup_strerror(ret)); goto cgroup_free_err; }