]> 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 16:19:39 +0000 (17:19 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/start.c

index 14f591d292877060c4f6df57528b248305879762..59fa7dcbbe4469bdaf84c2740794072199f5498c 100644 (file)
@@ -117,14 +117,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;
        }
@@ -132,7 +133,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;
@@ -874,7 +876,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;