]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: cgroup, freeze, unfreeze, wait: change fprintf => lxc_error 2434/head
author2xsec <dh48.jeong@samsung.com>
Wed, 27 Jun 2018 08:09:58 +0000 (17:09 +0900)
committer2xsec <dh48.jeong@samsung.com>
Wed, 27 Jun 2018 08:09:58 +0000 (17:09 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/tools/lxc_cgroup.c
src/lxc/tools/lxc_freeze.c
src/lxc/tools/lxc_unfreeze.c
src/lxc/tools/lxc_wait.c

index f97c440816cdc277b1686628f22120035cf39cff..16a10a11aa4dbac36d263d0512886f07d1cd718d 100644 (file)
@@ -37,7 +37,7 @@
 static int my_checker(const struct lxc_arguments* args)
 {
        if (!args->argc) {
-               lxc_error(args, "missing state object");
+               lxc_error(args, "Missing state object");
                return -1;
        }
 
@@ -95,44 +95,48 @@ int main(int argc, char *argv[])
        if (my_args.rcfile) {
                c->clear_config(c);
                if (!c->load_config(c, my_args.rcfile)) {
-                       fprintf(stderr, "Failed to load rcfile\n");
+                       lxc_error(&my_args, "Failed to load rcfile");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
+
                c->configfile = strdup(my_args.rcfile);
                if (!c->configfile) {
-                       fprintf(stderr, "Out of memory setting new config filename\n");
+                       lxc_error(&my_args, "Out of memory setting new config filename");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
        }
 
        if (!c->may_control(c)) {
-               fprintf(stderr, "Insufficent privileges to control %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
 
        if (!c->is_running(c)) {
-               fprintf(stderr, "'%s:%s' is not running\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "'%s:%s' is not running", my_args.lxcpath[0], my_args.name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
 
        if ((my_args.argc) > 1) {
                value = my_args.argv[1];
+
                if (!c->set_cgroup_item(c, state_object, value)) {
-                       fprintf(stderr, "failed to assign '%s' value to '%s' for '%s'\n",
-                               value, state_object, my_args.name);
+                       lxc_error(&my_args, "Failed to assign '%s' value to '%s' for '%s'",
+                                 value, state_object, my_args.name);
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
        } else {
                char buffer[TOOL_MAXPATHLEN];
-               int ret = c->get_cgroup_item(c, state_object, buffer, TOOL_MAXPATHLEN);
+               int ret;
+
+               ret = c->get_cgroup_item(c, state_object, buffer, TOOL_MAXPATHLEN);
                if (ret < 0) {
-                       fprintf(stderr, "failed to retrieve value of '%s' for '%s:%s'\n",
-                             state_object, my_args.lxcpath[0], my_args.name);
+                       lxc_error(&my_args, "Failed to retrieve value of '%s' for '%s:%s'",
+                                 state_object, my_args.lxcpath[0], my_args.name);
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
index 122564cca047f31c3d2f7158ea68ff6a211f12da..19e758c6f6fcb379a44131eb36f859ee9865d064 100644 (file)
@@ -75,33 +75,33 @@ int main(int argc, char *argv[])
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c) {
-               fprintf(stderr, "No such container: %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "No such container: %s:%s", my_args.lxcpath[0], my_args.name);
                exit(EXIT_FAILURE);
        }
 
        if (my_args.rcfile) {
                c->clear_config(c);
                if (!c->load_config(c, my_args.rcfile)) {
-                       fprintf(stderr, "Failed to load rcfile\n");
+                       lxc_error(&my_args, "Failed to load rcfile");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
                c->configfile = strdup(my_args.rcfile);
                if (!c->configfile) {
-                       fprintf(stderr, "Out of memory setting new config filename\n");
+                       lxc_error(&my_args, "Out of memory setting new config filename");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
        }
 
        if (!c->may_control(c)) {
-               fprintf(stderr, "Insufficent privileges to control %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
 
        if (!c->freeze(c)) {
-               fprintf(stderr, "Failed to freeze %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
index 5105d8703afc87520d676240d91a2a2084c92853..81aa05c19f5fcb4a28a27ca6af7f64c83246a503 100644 (file)
@@ -75,33 +75,35 @@ int main(int argc, char *argv[])
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c) {
-               fprintf(stderr, "No such container: %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "No such container: %s:%s", my_args.lxcpath[0], my_args.name);
                exit(EXIT_FAILURE);
        }
 
        if (!c->may_control(c)) {
-               fprintf(stderr, "Insufficent privileges to control %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
 
        if (my_args.rcfile) {
                c->clear_config(c);
+
                if (!c->load_config(c, my_args.rcfile)) {
-                       fprintf(stderr, "Failed to load rcfile\n");
+                       lxc_error(&my_args, "Failed to load rcfile");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
+
                c->configfile = strdup(my_args.rcfile);
                if (!c->configfile) {
-                       fprintf(stderr, "Out of memory setting new config filename\n");
+                       lxc_error(&my_args, "Out of memory setting new config filename");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
        }
 
        if (!c->unfreeze(c)) {
-               fprintf(stderr, "Failed to unfreeze %s:%s\n", my_args.lxcpath[0], my_args.name);
+               lxc_error(&my_args, "Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
index f768149e826c75197e34612c7a7add986e6b30d3..346c546ee09f79ad18cb5847f64f6849f0daefe7 100644 (file)
 #include "arguments.h"
 #include "tool_utils.h"
 
-static int my_checker(const struct lxc_argumentsargs)
+static int my_checker(const struct lxc_arguments *args)
 {
        if (!args->states) {
                lxc_error(args, "missing state option to wait for.");
                return -1;
        }
+
        return 0;
 }
 
-static int my_parser(struct lxc_arguments* args, int c, char* arg)
+static int my_parser(struct lxc_arguments *args, int c, char *arg)
 {
        switch (c) {
        case 's': args->states = optarg; break;
        case 't': args->timeout = atol(optarg); break;
        }
+
        return 0;
 }
 
@@ -105,21 +107,23 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
 
        if (!c->may_control(c)) {
-               fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
+               lxc_error(&my_args, "Insufficent privileges to control %s", c->name);
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
 
        if (my_args.rcfile) {
                c->clear_config(c);
+
                if (!c->load_config(c, my_args.rcfile)) {
-                       fprintf(stderr, "Failed to load rcfile\n");
+                       lxc_error(&my_args, "Failed to load rcfile");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
+
                c->configfile = strdup(my_args.rcfile);
                if (!c->configfile) {
-                       fprintf(stderr, "Out of memory setting new config filename\n");
+                       lxc_error(&my_args, "Out of memory setting new config filename");
                        lxc_container_put(c);
                        exit(EXIT_FAILURE);
                }
@@ -129,5 +133,6 @@ int main(int argc, char *argv[])
                lxc_container_put(c);
                exit(EXIT_FAILURE);
        }
+
        exit(EXIT_SUCCESS);
 }