From 37924895b5986830ca52a6409a272ea265fe69e9 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 21 Apr 2014 18:23:46 +0400 Subject: [PATCH] mount: don't open the same root twise Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- mount.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mount.c b/mount.c index 4685aae7c..270f53728 100644 --- a/mount.c +++ b/mount.c @@ -1776,10 +1776,15 @@ out: int mntns_collect_root(pid_t pid) { + static int mntns_root_pid = -1; + int fd, pfd; int ret; char path[PATH_MAX + 1]; + if (mntns_root_pid == pid) /* The required root is already opened */ + return get_service_fd(ROOT_FD_OFF); + close_service_fd(ROOT_FD_OFF); if (!(root_ns_mask & CLONE_NEWNS)) { @@ -1828,6 +1833,8 @@ int mntns_collect_root(pid_t pid) set_root: ret = install_service_fd(ROOT_FD_OFF, fd); + if (ret >= 0) + mntns_root_pid = pid; close(fd); return ret; }