From 4df7f012b9994ea54b1ad68176d8d45a57fa02f3 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Thu, 14 Nov 2013 12:48:41 -0600 Subject: [PATCH] lxc-start: if we pass in a config file, then don't use any loaded config MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Acked-by: Stéphane Graber --- 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 add2542f2..fe859dbee 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 2a70bc7fd..3cabf0d62 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 3a1237248..57b8e7834 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 -- 2.39.2