]> 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 15:38:10 +0000 (16:38 +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 adbd9b8f8c8900e547922be927205a0ec981fb37..b7982b6c8631fe9b198a8fa6d5271e0d65e3a56e 100644 (file)
@@ -379,6 +379,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));
@@ -392,6 +393,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);
@@ -482,10 +486,19 @@ out_free:
 
 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))
@@ -996,6 +1009,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 f1a41f59a40948389d2fb262fa4475dd0b290f3c..86b19a243fb4a79a30e18d0ac386252f9012f10d 100644 (file)
@@ -75,6 +75,7 @@ struct lxc_handler {
        void *cgroup_data;
        int ttysock[2]; // socketpair for child->parent tty fd passing
        bool backgrounded; // indicates whether should we close std{in,out,err} on start
+       int nsfd[LXC_NS_MAX];
 };