[CRIU] [PATCH 1/2] files: restore cwd after switching mntns

Andrey Vagin avagin at openvz.org
Wed Nov 18 03:04:25 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

Cc: Stanislav Kinsbursky <skinsbursky at openvz.org>
Reported-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 files-reg.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/files-reg.c b/files-reg.c
index 1e2daa9..ac334e7 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -423,6 +423,7 @@ void try_clean_remaps(int ns_fd)
 {
 	struct remap_info *ri;
 	int old_ns = -1;
+	int cwd_fd = -1;
 
 	if (list_empty(&remaps))
 		goto out;
@@ -436,6 +437,12 @@ void try_clean_remaps(int ns_fd)
 			return;
 		}
 
+		cwd_fd = open(".", O_DIRECTORY);
+		if (cwd_fd < 0) {
+			pr_perror("Unable to open cwd");
+			return;
+		}
+
 		if (setns(ns_fd, CLONE_NEWNS) < 0) {
 			close(old_ns);
 			pr_perror("`- Can't switch");
@@ -453,6 +460,15 @@ void try_clean_remaps(int ns_fd)
 		close(old_ns);
 	}
 
+	if (cwd_fd >= 0) {
+		if (fchdir(cwd_fd)) {
+			pr_perror("Unable to restore cwd");
+			close(cwd_fd);
+			return;
+		}
+		close(cwd_fd);
+	}
+
 out:
 	if (ns_fd >= 0)
 		close(ns_fd);
-- 
2.4.3



More information about the CRIU mailing list