All of lore.kernel.org
 help / color / mirror / Atom feed
* [user-cr][PATCH 1/2] restart: remount /proc for new tasks created with CLONE_NEWPID
@ 2010-02-15  9:07 Oren Laadan
       [not found] ` <1266224833-10902-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Oren Laadan @ 2010-02-15  9:07 UTC (permalink / raw)
  To: Serge Hallyn; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

Not doing this can be a pain for restarted software which relies
on /proc...

This builds on a patch by Serge Hallyn, but also aims to address the
future cases of hierarchical pid-ns:

1) Before mounting the new /proc, first umount the old one, which
isn't necessary anymore.

2) Perform the unshare() together with the remount of /proc, so it
will occur for every new pid-ns and not only for the first one.

Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
---
 restart.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/restart.c b/restart.c
index f3d33de..f42b456 100644
--- a/restart.c
+++ b/restart.c
@@ -30,6 +30,7 @@
 #include <asm/unistd.h>
 #include <sys/syscall.h>
 #include <sys/prctl.h>
+#include <sys/mount.h>
 
 #include <linux/sched.h>
 #include <linux/checkpoint.h>
@@ -273,6 +274,8 @@ int global_child_collected;
 int global_send_sigint = -1;
 int global_sent_sigint;
 
+static int ckpt_remount_proc(void);
+
 static int ckpt_build_tree(struct ckpt_ctx *ctx);
 static int ckpt_init_tree(struct ckpt_ctx *ctx);
 static int ckpt_set_creator(struct ckpt_ctx *ctx, struct task *task);
@@ -981,11 +984,36 @@ static int ckpt_probe_child(pid_t pid, char *str)
 	return 0;
 }
 
+/*
+ * Remount the /proc with a new instance: tasks that start a new
+ * pid-ns need a fresh mount of /proc to reflect their pid-ns.
+ */
+static int ckpt_remount_proc(void)
+{
+	if (unshare(CLONE_NEWNS | CLONE_FS) < 0) {
+		perror("unshare");
+		return -1;
+	}
+	if (umount2("/proc", MNT_DETACH) < 0) {
+		perror("umount -l /proc");
+		return -1;
+	}
+	if (mount("proc", "/proc", "proc", 0, NULL) < 0) {
+		perror("mount -t proc");
+		return -1;
+	}
+
+	return 0;
+}
+
 #ifdef CLONE_NEWPID
 static int __ckpt_coordinator(void *arg)
 {
 	struct ckpt_ctx *ctx = (struct ckpt_ctx *) arg;
 
+	if (ckpt_remount_proc() < 0)
+		return -1;
+
 	if (!ctx->args->wait)
 		close(ctx->pipe_coord[0]);
 
@@ -1850,6 +1878,10 @@ int ckpt_fork_stub(void *data)
 	struct task *task = (struct task *) data;
 	struct ckpt_ctx *ctx = task->ctx;
 
+	/* tasks with new pid-ns need new /proc mount */
+	if ((task->flags & TASK_NEWPID) && ckpt_remount_proc() < 0)
+		return -1;
+
 	/*
 	 * In restart into a new pid namespace (--pidns), coordinator
 	 * is the container init, hence if it terminated permatutely
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-02-16  9:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-15  9:07 [user-cr][PATCH 1/2] restart: remount /proc for new tasks created with CLONE_NEWPID Oren Laadan
     [not found] ` <1266224833-10902-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-02-15  9:07   ` [user-cr][PATCH 2/2] Add --mount-pty option to mount new devpts Oren Laadan
     [not found]     ` <1266224833-10902-2-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-02-15 14:33       ` Serge E. Hallyn
2010-02-15 20:50       ` Serge E. Hallyn
     [not found]         ` <20100215205003.GA16950-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-16  9:55           ` Oren Laadan
2010-02-15 14:31   ` [user-cr][PATCH 1/2] restart: remount /proc for new tasks created with CLONE_NEWPID Serge E. Hallyn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.