Skip to content

Commit

Permalink
cgroups: switch back to returning ints
Browse files Browse the repository at this point in the history
Whick makes for easier error checking and fallback code.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 26, 2021
1 parent ecb2b4d commit fd910d7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions src/lxc/cgroups/cgroup.h
Expand Up @@ -194,8 +194,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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/lxc/freezer.c
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions src/lxc/lxc.h
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/lxc/lxccontainer.c
Expand Up @@ -507,41 +507,41 @@ 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)
return false;

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)
return false;

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)
Expand Down

0 comments on commit fd910d7

Please sign in to comment.