From: Christian Brauner Date: Tue, 2 Feb 2021 21:28:01 +0000 (+0100) Subject: cgroups: switch back to returning ints X-Git-Tag: lxc-5.0.0~305^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ef7547f3d50ae4c83339e8f452c01a825b2c315;p=thirdparty%2Flxc.git cgroups: switch back to returning ints Whick makes for easier error checking and fallback code. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index c05e47906..e47cb339b 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -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; } diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h index ac702aeb9..68c12d33e 100644 --- a/src/lxc/cgroups/cgroup.h +++ b/src/lxc/cgroups/cgroup.h @@ -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) { diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c index b3ec92272..ae4d70f62 100644 --- a/src/lxc/freezer.c +++ b/src/lxc/freezer.c @@ -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; } diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index ec54aef83..f688b25c2 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -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 diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 2f2410c52..63cf63628 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -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)