]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
freezer: non-functional changes 2806/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 27 Jan 2019 01:04:21 +0000 (02:04 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 31 Jan 2019 10:34:46 +0000 (11:34 +0100)
Fix the coding style in a few files.

Fixes: db1228b35f3e ("Avoid hardcoded string length")
Fixes: 71fc9c046816 ("Avoid risk of "too far memory read"")
Fixes: 2341916a0367 ("Avoid double lxc-freeze/unfreeze")
Fixes: 9eb9ce3e4778 ("Update freezer.c")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/freezer.c
src/lxc/lxccontainer.c

index ad9052c7bc72dd4b95e6482de10fd147c360811c..953d9d8b83432dfebf3902504489b7602e5ca6f1 100644 (file)
@@ -51,11 +51,11 @@ static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
        int ret;
        char v[100];
        struct cgroup_ops *cgroup_ops;
-        const char *state;
+       const char *state;
        size_t state_len;
        lxc_state_t new_state = freeze ? FROZEN : THAWED;
 
-        state = lxc_state2str(new_state);
+       state = lxc_state2str(new_state);
        state_len = strlen(state);
 
        cgroup_ops = cgroup_init(conf);
@@ -65,19 +65,21 @@ static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
        ret = cgroup_ops->set(cgroup_ops, "freezer.state", state, name, lxcpath);
        if (ret < 0) {
                cgroup_exit(cgroup_ops);
-               ERROR("Failed to %s %s", (new_state == FROZEN ? "freeze" : "unfreeze"), name);
+               ERROR("Failed to %s %s",
+                     (new_state == FROZEN ? "freeze" : "unfreeze"), name);
                return -1;
        }
 
        for (;;) {
-               ret = cgroup_ops->get(cgroup_ops, "freezer.state", v, sizeof(v), name, lxcpath);
+               ret = cgroup_ops->get(cgroup_ops, "freezer.state", v, sizeof(v),
+                                     name, lxcpath);
                if (ret < 0) {
                        cgroup_exit(cgroup_ops);
                        ERROR("Failed to get freezer state of %s", name);
                        return -1;
                }
 
-               v[sizeof(v)-1] = '\0';
+               v[sizeof(v) - 1] = '\0';
                v[lxc_char_right_gc(v, strlen(v))] = '\0';
 
                ret = strncmp(v, state, state_len);
index 364c6c7a784efc452e81b27381ff9bf2fcf55571..7c826a9fd0a9da5d3a646bf1fd66801c87ac135f 100644 (file)
@@ -527,15 +527,12 @@ static bool do_lxcapi_freeze(struct lxc_container *c)
        int ret;
        lxc_state_t s;
 
-       if (!c)
+       if (!c || !c->lxc_conf)
                return false;
 
        s = lxc_getstate(c->name, c->config_path);
-       if (s != FROZEN) {
-         ret = lxc_freeze(c->lxc_conf, c->name, c->config_path);
-         if (ret < 0)
-           return false;
-       }
+       if (s != FROZEN)
+               return lxc_freeze(c->lxc_conf, c->name, c->config_path) == 0;
 
        return true;
 }
@@ -547,15 +544,12 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
        int ret;
        lxc_state_t s;
 
-       if (!c)
+       if (!c || !c->lxc_conf)
                return false;
 
        s = lxc_getstate(c->name, c->config_path);
-       if (s == FROZEN) {
-         ret = lxc_unfreeze(c->lxc_conf, c->name, c->config_path);
-         if (ret < 0)
-           return false;
-       }
+       if (s == FROZEN)
+               return lxc_unfreeze(c->lxc_conf, c->name, c->config_path) == 0;
 
        return true;
 }