From: Kamalesh Babulal Date: Tue, 22 Mar 2022 10:04:29 +0000 (+0530) Subject: cgxget.c: adopt err()/info() for printing messages X-Git-Tag: v3.0~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d147f686a9412668043d9c4afab1f1c409fbbca4;p=thirdparty%2Flibcgroup.git cgxget.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/cgxget.c b/src/tools/cgxget.c index 9602bb2f..5157f8f5 100644 --- a/src/tools/cgxget.c +++ b/src/tools/cgxget.c @@ -40,35 +40,34 @@ static const struct option long_options[] = { 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 [-nv] [-r ] [-g ] ", - program_name); - printf("[-a] ...\n"); - printf(" or: %s [-nv] [-r ] -g : ...\n", - program_name); - printf("Print parameter(s) of given group(s).\n"); - printf(" -1, --v1 Provided parameters are in "); - printf("v1 format\n"); - printf(" -2, --v2 Provided parameters are in "); - printf("v2 format\n"); - printf(" -i, --ignore-unmappable Do not return an error for settings "); - printf("that cannot be converted\n"); - printf(" -a, --all Print info about all relevant "); - printf("controllers\n"); - printf(" -g Controller which info should "); - printf("be displayed\n"); - printf(" -g : Control group which info "); - printf("should be displayed\n"); - printf(" -h, --help Display this help\n"); - printf(" -n Do not print headers\n"); - printf(" -r, --variable Define parameter to display\n"); - printf(" -v, --values-only Print only values, not "); - printf("parameter names\n"); + info("Usage: %s [-nv] [-r ] [-g ] ", + program_name); + info("[-a] ...\n"); + info(" or: %s [-nv] [-r ] -g : ...\n", + program_name); + info("Print parameter(s) of given group(s).\n"); + info(" -1, --v1 Provided parameters are in "); + info("v1 format\n"); + info(" -2, --v2 Provided parameters are in "); + info("v2 format\n"); + info(" -i, --ignore-unmappable Do not return an error for "); + info("settings that cannot be converted\n"); + info(" -a, --all Print info about all relevant"); + info(" controllers\n"); + info(" -g Controller which info should"); + info(" be displayed\n"); + info(" -g : Control group which info"); + info(" should be displayed\n"); + info(" -h, --help Display this help\n"); + info(" -n Do not print headers\n"); + info(" -r, --variable Define parameter to display\n"); + info(" -v, --values-only Print only values, not "); + info("parameter names\n"); } static int get_controller_from_name(const char * const name, @@ -82,8 +81,7 @@ static int get_controller_from_name(const char * const name, dot = strchr(*controller, '.'); if (dot == NULL) { - fprintf(stderr, "cgget: error parsing parameter name\n '%s'", - name); + err("cgget: error parsing parameter name\n '%s'", name); return ECGINVAL; } *dot = '\0'; @@ -189,8 +187,8 @@ static int parse_r_flag(struct cgroup **cg_list[], int * const cg_list_len, if (!cgc) { cgc = cgroup_add_controller(cg, cntl_value_controller); if (!cgc) { - fprintf(stderr, "cgget: cannot find controller '%s'\n", - cntl_value_controller); + err("cgget: cannot find controller '%s'\n", + cntl_value_controller); ret = ECGOTHER; goto out; } @@ -531,12 +529,12 @@ static int get_cv_value(struct control_value * const cv, */ tmp_ret = cgroup_test_subsys_mounted(controller_name); if (tmp_ret == 0) { - fprintf(stderr, "cgget: cannot find controller "); - fprintf(stderr, "'%s' in group '%s'\n", controller_name, - cg_name); + err("cgget: cannot find controller '%s' in ", + controller_name); + err("in group '%s'\n", cg_name); } else { - fprintf(stderr, "variable file read failed %s\n", - cgroup_strerror(ret)); + err("variable file read failed %s\n", + cgroup_strerror(ret)); } } @@ -741,12 +739,12 @@ static void print_control_values(const struct control_value * const cv, int mode) { if (mode & MODE_SHOW_NAMES) - printf("%s: ", cv->name); + info("%s: ", cv->name); if (cv->multiline_value) - printf("%s\n", cv->multiline_value); + info("%s\n", cv->multiline_value); else - printf("%s\n", cv->value); + info("%s\n", cv->value); } static void print_controller(const struct cgroup_controller * const cgc, @@ -763,13 +761,13 @@ static void print_cgroup(const struct cgroup * const cg, int mode) int i; if (mode & MODE_SHOW_HEADERS) - printf("%s:\n", cg->name); + info("%s:\n", cg->name); for (i = 0; i < cg->index; i++) print_controller(cg->controller[i], mode); if (mode & MODE_SHOW_HEADERS) - printf("\n"); + info("\n"); } static void print_cgroups(struct cgroup *cg_list[], int cg_list_len, int mode) @@ -840,8 +838,8 @@ int main(int argc, char *argv[]) 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; }