Skip to content

Commit

Permalink
api wrapper: only reset the current config if this call set it
Browse files Browse the repository at this point in the history
Instead of *always* resetting the current_config to null, we should only
reset it if this API call set it.

This allows nesting of API calls, e.g. c->checkpoint() can pass stuff into
criu.c, which can call c->init_pid() and not lose the ability to log stuff
afterwards.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
Tycho Andersen authored and stgraber committed Dec 10, 2015
1 parent 23820d5 commit 8164f0e
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/lxc/lxccontainer.c
Expand Up @@ -345,39 +345,71 @@ static bool do_lxcapi_is_defined(struct lxc_container *c)
static rettype fnname(struct lxc_container *c) \
{ \
rettype ret; \
current_config = c ? c->lxc_conf : NULL; \
bool reset_config = false; \
\
if (!current_config && c && c->lxc_conf) { \
current_config = c->lxc_conf; \
reset_config = true; \
} \
\
ret = do_##fnname(c); \
current_config = NULL; \
if (reset_config) \
current_config = NULL; \
\
return ret; \
}

#define WRAP_API_1(rettype, fnname, t1) \
static rettype fnname(struct lxc_container *c, t1 a1) \
{ \
rettype ret; \
current_config = c ? c->lxc_conf : NULL; \
bool reset_config = false; \
\
if (!current_config && c && c->lxc_conf) { \
current_config = c->lxc_conf; \
reset_config = true; \
} \
\
ret = do_##fnname(c, a1); \
current_config = NULL; \
if (reset_config) \
current_config = NULL; \
\
return ret; \
}

#define WRAP_API_2(rettype, fnname, t1, t2) \
static rettype fnname(struct lxc_container *c, t1 a1, t2 a2) \
{ \
rettype ret; \
current_config = c ? c->lxc_conf : NULL; \
bool reset_config = false; \
\
if (!current_config && c && c->lxc_conf) { \
current_config = c->lxc_conf; \
reset_config = true; \
} \
\
ret = do_##fnname(c, a1, a2); \
current_config = NULL; \
if (reset_config) \
current_config = NULL; \
\
return ret; \
}

#define WRAP_API_3(rettype, fnname, t1, t2, t3) \
static rettype fnname(struct lxc_container *c, t1 a1, t2 a2, t3 a3) \
{ \
rettype ret; \
current_config = c ? c->lxc_conf : NULL; \
bool reset_config = false; \
\
if (!current_config && c && c->lxc_conf) { \
current_config = c->lxc_conf; \
reset_config = true; \
} \
\
ret = do_##fnname(c, a1, a2, a3); \
current_config = NULL; \
if (reset_config) \
current_config = NULL; \
\
return ret; \
}

Expand Down

0 comments on commit 8164f0e

Please sign in to comment.