[CRIU] [PATCH 10/28] utils: Use daemon in open_fd_of_vpid() only its really need

Kirill Tkhai ktkhai at virtuozzo.com
Mon Jun 5 20:24:56 MSK 2017


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

diff --git a/criu/util.c b/criu/util.c
index 3cd55180f..effbce975 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -1233,19 +1233,26 @@ int open_fd_of_vpid(pid_t pid, int fd, int flags)
 {
 	struct pstree_item *item;
 	char path[64];
+	bool daemon;
 	int ret;
 
 	item = pstree_pid_by_virt(pid)->item;
+	daemon = !can_access_userns(item->user_ns);
 	ret = sprintf(path, "%d/fd/%d", item->pid->real, fd) + 1;
 	pr_info("Opening real [%s]\n", path);
+
+#define MAYBE_CALL_IN_DAEMON(func, path, len)	\
+	(daemon ? userns_call(func, UNS_FDOUT, path, len, -1) : func(path, -1, -1))
 	if (flags == O_RDONLY)
-		ret = userns_call(fn_open_proc_r, UNS_FDOUT, path, ret, -1);
+		ret = MAYBE_CALL_IN_DAEMON(fn_open_proc_r, path, ret);
 	else if (flags == O_WRONLY)
-		ret = userns_call(fn_open_proc_w, UNS_FDOUT, path, ret, -1);
+		ret = MAYBE_CALL_IN_DAEMON(fn_open_proc_w, path, ret);
 	else if (flags == O_RDWR)
-		ret = userns_call(fn_open_proc_rw, UNS_FDOUT, path, ret, -1);
+		ret = MAYBE_CALL_IN_DAEMON(fn_open_proc_rw, path, ret);
 	else
 		BUG();
+#undef MAYBE_CALL_IN_DAEMON
+
 	return ret;
 }
 



More information about the CRIU mailing list