tree-wide: port cgroup cleanup to call_cleaner(cgroup_exit)

parent 1e22a683
...@@ -1176,7 +1176,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, ...@@ -1176,7 +1176,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
*/ */
ret = cgroup_attach(name, lxcpath, pid); ret = cgroup_attach(name, lxcpath, pid);
if (ret) { if (ret) {
__do_cgroup_exit struct cgroup_ops *cgroup_ops = NULL; call_cleaner(cgroup_exit) struct cgroup_ops *cgroup_ops = NULL;
cgroup_ops = cgroup_init(conf); cgroup_ops = cgroup_init(conf);
if (!cgroup_ops) if (!cgroup_ops)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <sys/types.h> #include <sys/types.h>
#include "macro.h" #include "macro.h"
#include "memory_utils.h"
#define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup" #define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup"
#define DEFAULT_PAYLOAD_CGROUP_PREFIX "lxc.payload." #define DEFAULT_PAYLOAD_CGROUP_PREFIX "lxc.payload."
...@@ -171,20 +172,14 @@ struct cgroup_ops { ...@@ -171,20 +172,14 @@ struct cgroup_ops {
}; };
extern struct cgroup_ops *cgroup_init(struct lxc_conf *conf); extern struct cgroup_ops *cgroup_init(struct lxc_conf *conf);
extern void cgroup_exit(struct cgroup_ops *ops); extern void cgroup_exit(struct cgroup_ops *ops);
define_cleanup_function(struct cgroup_ops *, cgroup_exit);
extern void prune_init_scope(char *cg); extern void prune_init_scope(char *cg);
static inline void __auto_cgroup_exit__(struct cgroup_ops **ops)
{
if (*ops)
cgroup_exit(*ops);
}
extern int cgroup_attach(const char *name, const char *lxcpath, int64_t pid); extern int cgroup_attach(const char *name, const char *lxcpath, int64_t pid);
#define __do_cgroup_exit __attribute__((__cleanup__(__auto_cgroup_exit__)))
static inline bool pure_unified_layout(const struct cgroup_ops *ops) static inline bool pure_unified_layout(const struct cgroup_ops *ops)
{ {
return ops->cgroup_layout == CGROUP_LAYOUT_UNIFIED; return ops->cgroup_layout == CGROUP_LAYOUT_UNIFIED;
......
...@@ -35,7 +35,7 @@ static void notify_state_listeners(const char *name, const char *lxcpath, ...@@ -35,7 +35,7 @@ static void notify_state_listeners(const char *name, const char *lxcpath,
static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name, static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
const char *lxcpath) const char *lxcpath)
{ {
__do_cgroup_exit struct cgroup_ops *cgroup_ops = NULL; call_cleaner(cgroup_exit) struct cgroup_ops *cgroup_ops = NULL;
lxc_state_t new_state = freeze ? FROZEN : THAWED; lxc_state_t new_state = freeze ? FROZEN : THAWED;
int ret; int ret;
const char *state; const char *state;
......
...@@ -3308,8 +3308,7 @@ WRAP_API_1(bool, lxcapi_set_config_path, const char *) ...@@ -3308,8 +3308,7 @@ WRAP_API_1(bool, lxcapi_set_config_path, const char *)
static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsys, const char *value) static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsys, const char *value)
{ {
int ret; call_cleaner(cgroup_exit) struct cgroup_ops *cgroup_ops = NULL;
struct cgroup_ops *cgroup_ops;
if (!c) if (!c)
return false; return false;
...@@ -3321,19 +3320,15 @@ static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsy ...@@ -3321,19 +3320,15 @@ static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsy
if (!cgroup_ops) if (!cgroup_ops)
return false; return false;
ret = cgroup_ops->set(cgroup_ops, subsys, value, c->name, c->config_path); return cgroup_ops->set(cgroup_ops, subsys, value, c->name,
c->config_path) == 0;
cgroup_exit(cgroup_ops);
return ret == 0;
} }
WRAP_API_2(bool, lxcapi_set_cgroup_item, const char *, const char *) WRAP_API_2(bool, lxcapi_set_cgroup_item, const char *, const char *)
static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen) static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen)
{ {
int ret; call_cleaner(cgroup_exit) struct cgroup_ops *cgroup_ops = NULL;
struct cgroup_ops *cgroup_ops;
if (!c) if (!c)
return -1; return -1;
...@@ -3345,12 +3340,8 @@ static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys ...@@ -3345,12 +3340,8 @@ static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys
if (!cgroup_ops) if (!cgroup_ops)
return -1; return -1;
ret = cgroup_ops->get(cgroup_ops, subsys, retv, inlen, c->name, return cgroup_ops->get(cgroup_ops, subsys, retv, inlen, c->name,
c->config_path); c->config_path);
cgroup_exit(cgroup_ops);
return ret;
} }
WRAP_API_3(int, lxcapi_get_cgroup_item, const char *, char *, int) WRAP_API_3(int, lxcapi_get_cgroup_item, const char *, char *, int)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment