]> git.proxmox.com Git - mirror_lxc.git/commitdiff
api wrapper: only reset the current config if this call set it
authorTycho Andersen <tycho.andersen@canonical.com>
Wed, 2 Dec 2015 21:30:52 +0000 (14:30 -0700)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 10 Dec 2015 03:53:31 +0000 (22:53 -0500)
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>
src/lxc/lxccontainer.c

index 2804841894eb44d831b9faa9d82414f373b5776e..bc5d585147fd610d3a4caa2721acb14ccd605730 100644 (file)
@@ -345,9 +345,17 @@ out:
 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;                                                     \
 }
 
@@ -355,9 +363,17 @@ static rettype fnname(struct lxc_container *c)                             \
 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;                                                     \
 }
 
@@ -365,9 +381,17 @@ static rettype fnname(struct lxc_container *c, t1 a1)                      \
 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;                                                     \
 }
 
@@ -375,9 +399,17 @@ static rettype fnname(struct lxc_container *c, t1 a1, t2 a2)               \
 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;                                                     \
 }