]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgclassify: adopt err()/info() for printing messages
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 22 Mar 2022 10:04:10 +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/cgclassify.c

index e2f5e8a58e37f0e3578e4a94526b1d04ee96d477..9f19b8301e0dd3c90e52cc2b1bc9d0158914da5c 100644 (file)
 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] <controllers>:<path>] ", program_name);
-       printf("[--sticky | --cancel-sticky] <list of pids>\n");
-       printf("Move running task(s) to given cgroups\n");
-       printf("  -h, --help                    Display this help\n");
-       printf("  -g <controllers>:<path>       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] <controllers>:<path>] ", program_name);
+       info("[--sticky | --cancel-sticky] <list of pids>\n");
+       info("Move running task(s) to given cgroups\n");
+       info("  -h, --help                      Display this help\n");
+       info("  -g <controllers>:<path> 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;
                }