[lxc-devel] [PATCH v2 1/7] start.c:preserve_ns: added pid parameter

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Sep 30 10:18:51 UTC 2015


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/start.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/lxc/start.c b/src/lxc/start.c
index 0601333..1a7d5a3 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -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;
-- 
2.1.4




More information about the lxc-devel mailing list