]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-start: if we pass in a config file, then don't use any loaded config
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 14 Nov 2013 18:48:41 +0000 (12:48 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 14 Nov 2013 19:27:22 +0000 (13:27 -0600)
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@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc_start.c
src/lxc/lxccontainer.c
src/lxc/lxccontainer.h

index add2542f22da36cd9dfde116732681ca3c5386a4..fe859dbee608128c3ff6d43419d2162ce072d18b 100644 (file)
@@ -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);
index 2a70bc7fd4ac7f4989f38748d23edc2058e982b5..3cabf0d62a0533077b3957eebc0cc47d5bbf5bc7 100644 (file)
@@ -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;
index 3a12372486a3a99ca673e13695c44c87cc90ef12..57b8e7834e6c75a72806d9a63410d4d2ac15eb91 100644 (file)
@@ -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