[v4,08/19] mnt: Populate ROOT_FD_OFF

Submitted by Kirill Tkhai on Jan. 10, 2018, 2:01 p.m.

Details

Message ID 151559289320.31108.12786531329686328859.stgit@localhost.localdomain
State Accepted
Series "Introduce custom per-task service fds placement"
Commit a40231a0cea4ee5b84aaca1491cd6a3fca1b0c38
Headers show

Commit Message

Kirill Tkhai Jan. 10, 2018, 2:01 p.m.
This patch populates and occupies ROOT_FD_OFF fd,
which guarantees it won't be reused by ordinary fds.

v4: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/cr-restore.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index f9889099f..49d367e4c 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -512,6 +512,23 @@  static int setup_child_task_namespaces(struct pstree_item *item, struct ns_id **
 	return 0;
 }
 
+/* This actually populates and occupies ROOT_FD_OFF sfd */
+static int populate_root_fd_off(void)
+{
+	struct ns_id *mntns = NULL;
+	int ret;
+
+        if (root_ns_mask & CLONE_NEWNS) {
+                mntns = lookup_ns_by_id(root_item->ids->mnt_ns_id, &mnt_ns_desc);
+                BUG_ON(!mntns);
+        }
+
+	ret = mntns_get_root_fd(mntns);
+	if (ret < 0)
+		pr_err("Can't get root fd\n");
+	return ret >= 0 ? 0 : -1;
+}
+
 static rt_sigaction_t sigchld_act;
 /*
  * If parent's sigaction has blocked SIGKILL (which is non-sence),
@@ -1863,6 +1880,9 @@  static int restore_task_with_children(void *_arg)
 
 		if (root_prepare_shared())
 			goto err;
+
+		if (populate_root_fd_off())
+			goto err;
 	}
 
 	if ((ca->clone_flags & CLONE_NEWPID) && setup_current_pid_ns())