]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add lxc_conf_free()
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 6 Sep 2012 02:55:38 +0000 (21:55 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 12 Nov 2012 18:17:30 +0000 (13:17 -0500)
Then after lxcapi container->create(), free whatever lxc_conf may be
loaded and reload from the newly created configuration file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/lxccontainer.c

index dfdff54a5085a1d6ccbd91b731046a16fd7dee83..c110f6a27b896708222430e44c22a5cada780309 100644 (file)
@@ -2556,3 +2556,21 @@ int lxc_clear_hooks(struct lxc_conf *c)
        }
        return 0;
 }
+
+void lxc_conf_free(struct lxc_conf *conf)
+{
+       if (!conf)
+               return;
+       if (conf->console.path)
+               free(conf->console.path);
+       if (conf->rootfs.mount != LXCROOTFSMOUNT)
+               free(conf->rootfs.mount);
+       lxc_clear_config_network(conf);
+       if (conf->aa_profile)
+               free(conf->aa_profile);
+       lxc_clear_config_caps(conf);
+       lxc_clear_cgroups(conf, "lxc.cgroup");
+       lxc_clear_hooks(conf);
+       lxc_clear_mount_entries(conf);
+       free(conf);
+}
index 0c39916c920afa3797e06dbb0167e1f7d0d26a4a..dcf79fe5c4bdd8d1991bdee93affd103e495598e 100644 (file)
@@ -245,6 +245,7 @@ int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf);
  * Initialize the lxc configuration structure
  */
 extern struct lxc_conf *lxc_conf_init(void);
+extern void lxc_conf_free(struct lxc_conf *conf);
 
 extern int pin_rootfs(const char *rootfs);
 
index 471fecc2d3338fe713e44b88bbdb6113e5d31999..c8dc8c483515c54283effd570e95faaaa518780b 100644 (file)
@@ -215,6 +215,15 @@ static pid_t lxcapi_init_pid(struct lxc_container *c)
        return ret;
 }
 
+static bool load_config_locked(struct lxc_container *c, char *fname)
+{
+       if (!c->lxc_conf)
+               c->lxc_conf = lxc_conf_init();
+       if (c->lxc_conf && !lxc_config_read(fname, c->lxc_conf))
+               return true;
+       return false;
+}
+
 static bool lxcapi_load_config(struct lxc_container *c, char *alt_file)
 {
        bool ret = false;
@@ -229,10 +238,7 @@ static bool lxcapi_load_config(struct lxc_container *c, char *alt_file)
                return false;
        if (lxclock(c->slock, 0))
                return false;
-       if (!c->lxc_conf)
-               c->lxc_conf = lxc_conf_init();
-       if (c->lxc_conf && !lxc_config_read(fname, c->lxc_conf))
-               ret = true;
+       ret = load_config_locked(c, fname);
        lxcunlock(c->slock);
        return ret;
 }
@@ -596,11 +602,18 @@ again:
                goto out_unlock;
        }
 
-       if (WEXITSTATUS(status) != 0)
+       if (WEXITSTATUS(status) != 0) {
                ERROR("container creation template for %s exited with %d\n",
                      c->name, WEXITSTATUS(status));
-       else
-               bret = true;
+               goto out_unlock;
+       }
+
+       // 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;
+       bret = load_config_locked(c, c->configfile);
 
 out_unlock:
        lxcunlock(c->slock);