]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
start.c:preserve_ns: added pid parameter
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 6 Oct 2015 08:01:01 +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

index 5d1cb3634f189fcd5c8c8a8007be2926cb174df2..adbd9b8f8c8900e547922be927205a0ec981fb37 100644 (file)
@@ -124,14 +124,15 @@ static void close_ns(int ns_fd[LXC_NS_MAX]) {
        }
 }
 
-static int preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags) {
+static int preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags, pid_t pid) {
        int i, saved_errno;
        char path[MAXPATHLEN];
 
        for (i = 0; i < LXC_NS_MAX; i++)
                ns_fd[i] = -1;
 
-       if (access("/proc/self/ns", X_OK)) {
+       snprintf(path, MAXPATHLEN, "/proc/%d/ns", pid);
+       if (access(path, X_OK)) {
                WARN("Kernel does not support attach; preserve_ns ignored");
                return 0;
        }
@@ -139,7 +140,8 @@ static int preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags) {
        for (i = 0; i < LXC_NS_MAX; i++) {
                if ((clone_flags & ns_info[i].clone_flag) == 0)
                        continue;
-               snprintf(path, MAXPATHLEN, "/proc/self/ns/%s", ns_info[i].proc_name);
+               snprintf(path, MAXPATHLEN, "/proc/%d/ns/%s", pid,
+                        ns_info[i].proc_name);
                ns_fd[i] = open(path, O_RDONLY | O_CLOEXEC);
                if (ns_fd[i] < 0)
                        goto error;
@@ -973,7 +975,7 @@ static int lxc_spawn(struct lxc_handler *handler)
                        INFO("failed to pin the container's rootfs");
        }
 
-       if (preserve_ns(saved_ns_fd, preserve_mask) < 0)
+       if (preserve_ns(saved_ns_fd, preserve_mask, getpid()) < 0)
                goto out_delete_net;
        if (attach_ns(handler->conf->inherit_ns_fd) < 0)
                goto out_delete_net;