[lxc-devel] [PATCH 1/3] api wrapper: only reset the current config if this call set it

Tycho Andersen tycho.andersen at canonical.com
Wed Dec 2 21:30:52 UTC 2015


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 at canonical.com>
---
 src/lxc/lxccontainer.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 69816da..613e894 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -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;							\
 }
 
-- 
2.6.2



More information about the lxc-devel mailing list