*/
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)
#include <sys/types.h>
#include "macro.h"
+#include "memory_utils.h"
#define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup"
#define DEFAULT_PAYLOAD_CGROUP_PREFIX "lxc.payload."
};
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;
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;
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;
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;
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)