[CRIU] [PATCH] restore: use /proc/self/mountinfo for collecting mounts fo the root task
Andrey Vagin
avagin at openvz.org
Fri Aug 8 03:04:46 PDT 2014
If the root task is forked in a new pidns, it can't use its pid for
accessing /proc, because this proc belongs to the source pidns.
Reported-by: Tycho Andersen <tycho.andersen at canonical.com>
Cc: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
mount.c | 2 +-
proc_parse.c | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/mount.c b/mount.c
index e0e88ea..3287282 100644
--- a/mount.c
+++ b/mount.c
@@ -1911,7 +1911,7 @@ int prepare_mnt_ns(void)
{
int ret = -1;
struct mount_info *mis, *old;
- struct ns_id ns = { .pid = getpid(), .nd = &mnt_ns_desc };
+ struct ns_id ns = { .pid = PROC_SELF, .nd = &mnt_ns_desc };
if (!(root_ns_mask & CLONE_NEWNS))
return rst_collect_local_mntns();
diff --git a/proc_parse.c b/proc_parse.c
index 66a1e12..e50063f 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -944,7 +944,10 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
FILE *f;
char str[1024];
- snprintf(str, sizeof(str), "/proc/%d/mountinfo", pid);
+ if (pid == PROC_SELF)
+ snprintf(str, sizeof(str), "/proc/self/mountinfo");
+ else
+ snprintf(str, sizeof(str), "/proc/%d/mountinfo", pid);
f = fopen(str, "r");
if (!f) {
pr_perror("Can't open %d mountinfo", pid);
--
1.9.3
More information about the CRIU
mailing list