[CRIU] [PATCH 2/5] mnt_ns: Move open_proc() up in prepare_mnt_ns()

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 7 18:15:37 MSK 2017


The both branches need this, so move it up.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/mount.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index b7c4785b1..9a08506dd 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -3023,9 +3023,11 @@ int prepare_mnt_ns(void)
 			goto err;
 		}
 
-		if (nsid->type == NS_ROOT) {
-			int fd;
+		fd = open_proc(PROC_SELF, "ns/mnt");
+		if (fd < 0)
+			goto err;
 
+		if (nsid->type == NS_ROOT) {
 			/*
 			 * We need to create a mount namespace which will be
 			 * used to clean up remap files
@@ -3034,9 +3036,6 @@ int prepare_mnt_ns(void)
 			 * namespace, because there are file descriptors
 			 * linked with it (e.g. to bind-mount slave pty-s).
 			 */
-			fd = open_proc(PROC_SELF, "ns/mnt");
-			if (fd < 0)
-				goto err;
 			if (setns(rst, CLONE_NEWNS)) {
 				pr_perror("Can't restore mntns back");
 				goto err;
@@ -3045,9 +3044,7 @@ int prepare_mnt_ns(void)
 			rst = fd;
 		} else {
 			/* Pin one with a file descriptor */
-			nsid->mnt.ns_fd = open_proc(PROC_SELF, "ns/mnt");
-			if (nsid->mnt.ns_fd < 0)
-				goto err;
+			nsid->mnt.ns_fd = fd;
 		}
 
 		/* Set its root */



More information about the CRIU mailing list