From 70d35640b9a2e5c5026527bef8228e4469590fd4 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Thu, 7 Jul 2016 18:50:47 +0800 Subject: [PATCH] mount proc filesystem of container in enter_container Signed-off-by: Gao feng --- src/container.c | 4 ++-- src/exec.c | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/container.c b/src/container.c index 69b3c34..d03e519 100644 --- a/src/container.c +++ b/src/container.c @@ -268,8 +268,8 @@ static int container_setup_mount(struct hyper_container *container) hyper_mkdir("./dev"); hyper_mkdir("./lib/modules"); - if (mount("proc", "./proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0 || - mount("sysfs", "./sys", "sysfs", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0 || + // mount proc filesystem when the container init process running in the pidns of podinit + if (mount("sysfs", "./sys", "sysfs", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0 || mount("devtmpfs", "./dev", "devtmpfs", MS_NOSUID, NULL) < 0) { perror("mount basic filesystem for container failed"); return -1; diff --git a/src/exec.c b/src/exec.c index a06602a..eaeda37 100644 --- a/src/exec.c +++ b/src/exec.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -518,8 +519,14 @@ static int hyper_enter_container(struct hyper_pod *pod, /* TODO: wait for container finishing setup root */ chdir("/"); - ret = 0; + /* already in pidns & mntns of container, mount proc filesystem */ + if (exec->init && mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) < 0) { + perror("fail to mount proc filesystem for container"); + goto out; + } + + ret = 0; out: close(ipcns); close(utsns);