]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: switch back to returning ints
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 2 Feb 2021 21:28:01 +0000 (22:28 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 2 Feb 2021 21:56:10 +0000 (22:56 +0100)
Whick makes for easier error checking and fallback code.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/cgroups/cgroup.h
src/lxc/freezer.c
src/lxc/lxc.h
src/lxc/lxccontainer.c

index c05e47906af2f6ba47289399bf78bfb320c01b76..e47cb339b497d99a06d1208bd0462f1463f75995 100644 (file)
@@ -3592,7 +3592,7 @@ static int __cgroup_freeze(int unified_fd,
        return log_trace(0, "Container now %s", (state_num == 1) ? "frozen" : "unfrozen");
 }
 
-bool cgroup_freeze(const char *name, const char *lxcpath, int timeout)
+int cgroup_freeze(const char *name, const char *lxcpath, int timeout)
 {
        __do_close int unified_fd = -EBADF;
        int ret;
@@ -3609,10 +3609,10 @@ bool cgroup_freeze(const char *name, const char *lxcpath, int timeout)
                              "Failed to create epoll instance to wait for container freeze",
                              "Failed to wait for container to be frozen");
        lxc_cmd_notify_state_listeners(name, lxcpath, !ret ? FROZEN : RUNNING);
-       return ret == 0;
+       return ret;
 }
 
-bool cgroup_unfreeze(const char *name, const char *lxcpath, int timeout)
+int cgroup_unfreeze(const char *name, const char *lxcpath, int timeout)
 {
        __do_close int unified_fd = -EBADF;
        int ret;
@@ -3629,5 +3629,5 @@ bool cgroup_unfreeze(const char *name, const char *lxcpath, int timeout)
                              "Failed to create epoll instance to wait for container freeze",
                              "Failed to wait for container to be frozen");
        lxc_cmd_notify_state_listeners(name, lxcpath, !ret ? RUNNING : FROZEN);
-       return ret == 0;
+       return ret;
 }
index ac702aeb928b31e591f862350120646183263423..68c12d33e191e7876ec0587fa014bc97aee2fe78 100644 (file)
@@ -195,8 +195,8 @@ __hidden extern int cgroup_get(const char *name, const char *lxcpath,
                                const char *filename, char *buf, size_t len);
 __hidden extern int cgroup_set(const char *name, const char *lxcpath,
                                const char *filename, const char *value);
-__hidden extern bool cgroup_freeze(const char *name, const char *lxcpath, int timeout);
-__hidden extern bool cgroup_unfreeze(const char *name, const char *lxcpath, int timeout);
+__hidden extern int cgroup_freeze(const char *name, const char *lxcpath, int timeout);
+__hidden extern int cgroup_unfreeze(const char *name, const char *lxcpath, int timeout);
 
 static inline bool pure_unified_layout(const struct cgroup_ops *ops)
 {
index b3ec92272c5be5f06c89fed007d7a96a3566dcd8..ae4d70f62ba2b6163cb2e9148d66f32d8a6d6e2c 100644 (file)
@@ -68,7 +68,7 @@ static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
        return 0;
 }
 
-bool lxc_freeze(struct lxc_conf *conf, const char *name, const char *lxcpath)
+int lxc_freeze(struct lxc_conf *conf, const char *name, const char *lxcpath)
 {
        int ret;
 
@@ -78,10 +78,10 @@ bool lxc_freeze(struct lxc_conf *conf, const char *name, const char *lxcpath)
        else
                ret = do_freeze_thaw(true, conf, name, lxcpath);
        lxc_cmd_notify_state_listeners(name, lxcpath, !ret ? FROZEN : RUNNING);
-       return ret == 0;
+       return ret;
 }
 
-bool lxc_unfreeze(struct lxc_conf *conf, const char *name, const char *lxcpath)
+int lxc_unfreeze(struct lxc_conf *conf, const char *name, const char *lxcpath)
 {
        int ret;
 
@@ -91,5 +91,5 @@ bool lxc_unfreeze(struct lxc_conf *conf, const char *name, const char *lxcpath)
        else
                ret = do_freeze_thaw(false, conf, name, lxcpath);
        lxc_cmd_notify_state_listeners(name, lxcpath, !ret ? RUNNING : FROZEN);
-       return ret == 0;
+       return ret;
 }
index ec54aef83f62fc309c0fd92c7d2d57df61204879..f688b25c264a6b399486c03966ac1705d4328760 100644 (file)
@@ -62,14 +62,14 @@ __hidden extern int lxc_monitor_close(int fd);
  * @name : the container name
  * Returns 0 on success, < 0 otherwise
  */
-__hidden extern bool lxc_freeze(struct lxc_conf *conf, const char *name, const char *lxcpath);
+__hidden extern int lxc_freeze(struct lxc_conf *conf, const char *name, const char *lxcpath);
 
 /*
  * Unfreeze all previously frozen tasks.
  * @name : the name of the container
  * Return 0 on success, < 0 otherwise
  */
-__hidden extern bool lxc_unfreeze(struct lxc_conf *conf, const char *name, const char *lxcpath);
+__hidden extern int lxc_unfreeze(struct lxc_conf *conf, const char *name, const char *lxcpath);
 
 /*
  * Retrieve the container state
index 2f2410c52583c6c1b68d5b86573101df7a7345b0..63cf636288e2ea07ce27997a643fbabcf134231e 100644 (file)
@@ -507,7 +507,7 @@ WRAP_API(bool, lxcapi_is_running)
 
 static bool do_lxcapi_freeze(struct lxc_container *c)
 {
-       bool bret = true;
+       int ret = 0;
        lxc_state_t s;
 
        if (!c || !c->lxc_conf)
@@ -515,19 +515,19 @@ static bool do_lxcapi_freeze(struct lxc_container *c)
 
        s = lxc_getstate(c->name, c->config_path);
        if (s != FROZEN) {
-               bret = cgroup_freeze(c->name, c->config_path, -1);
-               if (!bret && errno == ENOCGROUP2)
-                       bret = lxc_freeze(c->lxc_conf, c->name, c->config_path);
+               ret = cgroup_freeze(c->name, c->config_path, -1);
+               if (ret == -ENOCGROUP2)
+                       ret = lxc_freeze(c->lxc_conf, c->name, c->config_path);
        }
 
-       return bret;
+       return ret == 0;
 }
 
 WRAP_API(bool, lxcapi_freeze)
 
 static bool do_lxcapi_unfreeze(struct lxc_container *c)
 {
-       bool bret = true;
+       int ret = 0;
        lxc_state_t s;
 
        if (!c || !c->lxc_conf)
@@ -535,13 +535,13 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
 
        s = lxc_getstate(c->name, c->config_path);
        if (s == FROZEN) {
-               bret = cgroup_unfreeze(c->name, c->config_path, -1);
-               if (!bret && errno == ENOCGROUP2)
-                       bret = lxc_unfreeze(c->lxc_conf, c->name, c->config_path);
+               ret = cgroup_unfreeze(c->name, c->config_path, -1);
+               if (ret == -ENOCGROUP2)
+                       ret = lxc_unfreeze(c->lxc_conf, c->name, c->config_path);
        }
 
 
-       return bret;
+       return ret == 0;
 }
 
 WRAP_API(bool, lxcapi_unfreeze)