[CRIU] [PATCH 08/11] files: close_old_fds before forking children (v2)

Andrey Vagin avagin at openvz.org
Fri Jan 11 09:16:24 EST 2013


A few processes can share one fd table. Each process has own set of
service file descriptors and a process knows nothing about servic fds
of another processes. So if two process share one fd table,
close_old_fds will close servic descriptors of another process.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c    | 7 +++++--
 files.c         | 7 +------
 include/files.h | 1 +
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index b2c614a..57da009 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -993,10 +993,13 @@ static int restore_task_with_children(void *_arg)
 	int ret;
 	sigset_t blockmask;
 
-	close_safe(&ca->fd);
-
 	current = ca->item;
 
+	close_safe(&ca->fd);
+	ret = close_old_fds(current);
+	if (ret)
+		exit(1);
+
 	pid = getpid();
 	if (current->pid.virt != pid) {
 		pr_err("Pid %d do not match expected %d\n", pid, current->pid.virt);
diff --git a/files.c b/files.c
index d59cee6..1e78ef8 100644
--- a/files.c
+++ b/files.c
@@ -496,7 +496,7 @@ static int open_fdinfos(int pid, struct list_head *list, int state)
 	return ret;
 }
 
-static int close_old_fds(struct pstree_item *me)
+int close_old_fds(struct pstree_item *me)
 {
 	DIR *dir;
 	struct dirent *de;
@@ -531,10 +531,6 @@ int prepare_fds(struct pstree_item *me)
 	u32 ret;
 	int state;
 
-	ret = close_old_fds(me);
-	if (ret)
-		goto err;
-
 	pr_info("Opening fdinfo-s\n");
 
 	for (state = 0; state < ARRAY_SIZE(states); state++) {
@@ -560,7 +556,6 @@ int prepare_fds(struct pstree_item *me)
 			break;
 	}
 
-err:
 	tty_fini_fds();
 	return ret;
 }
diff --git a/include/files.h b/include/files.h
index 40d115c..9d829f2 100644
--- a/include/files.h
+++ b/include/files.h
@@ -94,6 +94,7 @@ extern int get_filemap_fd(int pid, VmaEntry *vma_entry);
 extern int prepare_fs(int pid);
 extern int set_fd_flags(int fd, int flags);
 
+extern int close_old_fds(struct pstree_item *me);
 #ifndef AT_EMPTY_PATH
 #define AT_EMPTY_PATH 0x1000
 #endif
-- 
1.7.11.7



More information about the CRIU mailing list