]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
preserve container namespace
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 6 Oct 2015 08:01:02 +0000 (10:01 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 7 Oct 2015 16:21:11 +0000 (17:21 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/start.c
src/lxc/start.h

index 59fa7dcbbe4469bdaf84c2740794072199f5498c..3cbb049c6dc215a5b9a6157898f7dd99adf0d3ea 100644 (file)
@@ -357,6 +357,7 @@ out_sigfd:
 
 struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char *lxcpath)
 {
+       int i;
        struct lxc_handler *handler;
 
        handler = malloc(sizeof(*handler));
@@ -369,6 +370,9 @@ struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char
        handler->lxcpath = lxcpath;
        handler->pinfd = -1;
 
+       for (i = 0; i < LXC_NS_MAX; i++)
+               handler->nsfd[i] = -1;
+
        lsm_init();
 
        handler->name = strdup(name);
@@ -464,10 +468,19 @@ out_free:
 
 static void lxc_fini(const char *name, struct lxc_handler *handler)
 {
+       int i;
+
        /* The STOPPING state is there for future cleanup code
         * which can take awhile
         */
        lxc_set_state(name, handler, STOPPING);
+
+       for (i = 0; i < LXC_NS_MAX; i++) {
+               if (handler->nsfd[i] != -1) {
+                       close(handler->nsfd[i]);
+                       handler->nsfd[i] = -1;
+               }
+       }
        lxc_set_state(name, handler, STOPPED);
 
        if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL))
@@ -897,6 +910,11 @@ static int lxc_spawn(struct lxc_handler *handler)
                goto out_delete_net;
        }
 
+       if (preserve_ns(handler->nsfd, handler->clone_flags, handler->pid) < 0) {
+           ERROR("failed to store namespace references");
+           goto out_delete_net;
+       }
+
        if (attach_ns(saved_ns_fd))
                WARN("failed to restore saved namespaces");
 
index ca7891cdd920f97010ad1683c449e4a9a02b2fef..7afa37a3996e836a660521c8c79c0a8ae3719fb6 100644 (file)
@@ -72,6 +72,7 @@ struct lxc_handler {
        int pinfd;
        const char *lxcpath;
        void *cgroup_data;
+       int nsfd[LXC_NS_MAX];
 };
 
 extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *, const char *);