]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgset.c: adopt err()/info() for printing messages
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 22 Mar 2022 10:04:25 +0000 (15:34 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 24 Mar 2022 14:03:42 +0000 (08:03 -0600)
Replace usage of fprintf(stderr, ...) with err() and printf(...) with
info().

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

index 769638096c72e479fdd7850f6101318f92cdc072..999d40456c1fb48d002f9bd60edac2f2da482f3a 100644 (file)
@@ -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 <name=value>] <cgroup_path> ...\n",
-              program_name);
-       printf("   or: %s --copy-from <source_cgroup_path> ", program_name);
-       printf("<cgroup_path> ...\n");
-       printf("Set the parameters of given cgroup(s)\n");
-       printf("  -r, --variable <name>                 Define parameter ");
-       printf("to set\n");
-       printf("  --copy-from <source_cgroup_path>      Control group whose ");
-       printf("parameters will be copied\n");
+       info("Usage: %s [-r <name=value>] <cgroup_path> ...\n", program_name);
+       info("   or: %s --copy-from <source_cgroup_path> ", program_name);
+       info("<cgroup_path> ...\n");
+       info("Set the parameters of given cgroup(s)\n");
+       info("  -r, --variable <name>                   Define parameter ");
+       info("to set\n");
+       info("  --copy-from <source_cgroup_path>        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 <name=value> ", argv[0]);
-               fprintf(stderr, "<relative path to cgroup>\n");
+               err("Usage is %s -r <name=value> ", argv[0]);
+               err("<relative path to cgroup>\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;
                }