[lxc-devel] [PATCH 1/1] lxc-start: if we pass in a config file, then don't use any loaded config

Serge Hallyn serge.hallyn at ubuntu.com
Thu Nov 14 18:48:41 UTC 2013


To do this, add a c->clear_config() helper to the api.

(this fixes the bug https://bugs.launchpad.net/bugs/1251352)

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/lxc_start.c    |  1 +
 src/lxc/lxccontainer.c | 16 +++++++++++-----
 src/lxc/lxccontainer.h |  2 ++
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index add2542..fe859db 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -187,6 +187,7 @@ int main(int argc, char *argv[])
 			ERROR("Failed to create lxc_container");
 			return err;
 		}
+		c->clear_config(c);
 		if (!c->load_config(c, rcfile)) {
 			ERROR("Failed to load rcfile");
 			lxc_container_put(c);
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 2a70bc7..3cabf0d 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -1151,6 +1151,14 @@ out_error:
 	return true;
 }
 
+static void lxcapi_clear_config(struct lxc_container *c)
+{
+	if (c && c->lxc_conf) {
+		lxc_conf_free(c->lxc_conf);
+		c->lxc_conf = NULL;
+	}
+}
+
 static bool lxcapi_destroy(struct lxc_container *c);
 /*
  * lxcapi_create:
@@ -1280,9 +1288,7 @@ static bool lxcapi_create(struct lxc_container *c, const char *t,
 
 	// now clear out the lxc_conf we have, reload from the created
 	// container
-	if (c->lxc_conf)
-		lxc_conf_free(c->lxc_conf);
-	c->lxc_conf = NULL;
+	lxcapi_clear_config(c);
 
 	if (t) {
 		if (!prepend_lxc_header(c->configfile, tpath, argv)) {
@@ -3093,8 +3099,7 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
 	if (ongoing_create(c) == 2) {
 		ERROR("Error: %s creation was not completed", c->name);
 		lxcapi_destroy(c);
-		lxc_conf_free(c->lxc_conf);
-		c->lxc_conf = NULL;
+		lxcapi_clear_config(c);
 	}
 
 	// assign the member functions
@@ -3122,6 +3127,7 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
 	c->createl = lxcapi_createl;
 	c->shutdown = lxcapi_shutdown;
 	c->reboot = lxcapi_reboot;
+	c->clear_config = lxcapi_clear_config;
 	c->clear_config_item = lxcapi_clear_config_item;
 	c->get_config_item = lxcapi_get_config_item;
 	c->get_cgroup_item = lxcapi_get_cgroup_item;
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index 3a12372..57b8e78 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -85,6 +85,8 @@ struct lxc_container {
 	bool (*reboot)(struct lxc_container *c);
 	/* send SIGPWR.  if timeout is not 0 or -1, do a hard stop after timeout seconds */
 	bool (*shutdown)(struct lxc_container *c, int timeout);
+	/* completely clear a configuration */
+	void (*clear_config)(struct lxc_container *c);
 	/* clear all network or capability items in the in-memory configuration */
 	bool (*clear_config_item)(struct lxc_container *c, const char *key);
 	/* print a config item to a in-memory string allocated by the caller.  Return
-- 
1.8.3.2





More information about the lxc-devel mailing list