From: Christian Brauner Date: Sun, 15 Mar 2020 00:55:24 +0000 (+0100) Subject: tree-wide: port cgroup cleanup to call_cleaner(cgroup_exit) X-Git-Tag: lxc-4.0.0~30^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a07663367606d138d62323e245cf289706640f6;p=thirdparty%2Flxc.git tree-wide: port cgroup cleanup to call_cleaner(cgroup_exit) Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 26fd753ec..d147a59ed 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -1176,7 +1176,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, */ ret = cgroup_attach(name, lxcpath, pid); 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); if (!cgroup_ops) diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h index 309f31fae..9f44ad51b 100644 --- a/src/lxc/cgroups/cgroup.h +++ b/src/lxc/cgroups/cgroup.h @@ -8,6 +8,7 @@ #include #include "macro.h" +#include "memory_utils.h" #define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup" #define DEFAULT_PAYLOAD_CGROUP_PREFIX "lxc.payload." @@ -171,20 +172,14 @@ struct cgroup_ops { }; extern struct cgroup_ops *cgroup_init(struct lxc_conf *conf); + extern void cgroup_exit(struct cgroup_ops *ops); +define_cleanup_function(struct cgroup_ops *, cgroup_exit); 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); -#define __do_cgroup_exit __attribute__((__cleanup__(__auto_cgroup_exit__))) - static inline bool pure_unified_layout(const struct cgroup_ops *ops) { return ops->cgroup_layout == CGROUP_LAYOUT_UNIFIED; diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c index 13b775615..dbb70f61d 100644 --- a/src/lxc/freezer.c +++ b/src/lxc/freezer.c @@ -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, 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; int ret; const char *state; diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 0c69670aa..42e3b562f 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -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) { - int ret; - struct cgroup_ops *cgroup_ops; + call_cleaner(cgroup_exit) struct cgroup_ops *cgroup_ops = NULL; if (!c) return false; @@ -3321,19 +3320,15 @@ static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsy if (!cgroup_ops) return false; - ret = cgroup_ops->set(cgroup_ops, subsys, value, c->name, c->config_path); - - cgroup_exit(cgroup_ops); - - return ret == 0; + return cgroup_ops->set(cgroup_ops, subsys, value, c->name, + c->config_path) == 0; } 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) { - int ret; - struct cgroup_ops *cgroup_ops; + call_cleaner(cgroup_exit) struct cgroup_ops *cgroup_ops = NULL; if (!c) return -1; @@ -3345,12 +3340,8 @@ static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys if (!cgroup_ops) return -1; - ret = cgroup_ops->get(cgroup_ops, subsys, retv, inlen, c->name, - c->config_path); - - cgroup_exit(cgroup_ops); - - return ret; + return cgroup_ops->get(cgroup_ops, subsys, retv, inlen, c->name, + c->config_path); } WRAP_API_3(int, lxcapi_get_cgroup_item, const char *, char *, int)