[CRIU] [PATCH 50/78] infect: Remove criu util.h from infect

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:36:35 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

This includes

* The close_safe() routine for infect
* Callback for opening proc files on infect_ctx

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/include/infect.h   |  5 +++++
 criu/infect.c           | 16 +++++++++++-----
 criu/parasite-syscall.c |  1 +
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/criu/include/infect.h b/criu/include/infect.h
index a161ae238139..51c6247c4d20 100644
--- a/criu/include/infect.h
+++ b/criu/include/infect.h
@@ -89,6 +89,9 @@ extern k_rtsigset_t *compel_task_sigmask(struct parasite_ctl *ctl);
 
 struct rt_sigframe;
 
+typedef int (*open_proc_fn)(int pid, int mode, const char *fmt, ...)
+	__attribute__ ((__format__ (__printf__, 3, 4)));
+
 struct infect_ctx {
 	int	*p_sock;
 
@@ -103,6 +106,8 @@ struct infect_ctx {
 	unsigned long		flags;			/* fine-tune (e.g. faults) */
 
 	void (*child_handler)(int, siginfo_t *, void *);	/* hander for SIGCHLD deaths */
+
+	open_proc_fn open_proc;
 };
 
 extern struct infect_ctx *compel_infect_ctx(struct parasite_ctl *);
diff --git a/criu/infect.c b/criu/infect.c
index 515c31e8be2a..dff9d31444a4 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -6,6 +6,7 @@
 #include <signal.h>
 #include <sys/mman.h>
 #include <stdio.h>
+#include <fcntl.h>
 #include <linux/seccomp.h>
 
 #include "pie-relocs.h"
@@ -15,9 +16,6 @@
 #include "common/xmalloc.h"
 #include "lock.h"
 
-#include <fcntl.h>
-#include "util.h"
-
 #include "uapi/std/syscall-codes.h"
 #include "uapi/std/asm/syscall-types.h"
 #include "compel/include/asm/ptrace.h"
@@ -46,6 +44,14 @@
 
 #define SI_EVENT(_si_code)	(((_si_code) & 0xFFFF) >> 8)
 
+static inline void close_safe(int *pfd)
+{
+	if (*pfd > -1) {
+		close(*pfd);
+		*pfd = -1;
+	}
+}
+
 int compel_stop_task(int pid)
 {
 	int ret;
@@ -626,7 +632,7 @@ static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size)
 
 	ctl->map_length = round_up(size, page_size());
 
-	fd = open_proc_rw(ctl->rpid, "map_files/%p-%p",
+	fd = ctl->ictx.open_proc(ctl->rpid, O_RDWR, "map_files/%p-%p",
 		 ctl->remote_map, ctl->remote_map + ctl->map_length);
 	if (fd < 0)
 		return -1;
@@ -685,7 +691,7 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size)
 		return fd;
 
 	ctl->map_length = round_up(size, page_size());
-	lfd = open_proc_rw(ctl->rpid, "fd/%d", fd);
+	lfd = ctl->ictx.open_proc(ctl->rpid, O_RDWR, "fd/%d", fd);
 	if (lfd < 0)
 		goto err_cure;
 
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index e7b6084e6f92..94f5df49163b 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -543,6 +543,7 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 
 	ictx = compel_infect_ctx(ctl);
 
+	ictx->open_proc = do_open_proc;
 	ictx->child_handler = sigchld_handler;
 	ictx->p_sock = &dmpi(item)->netns->net.seqsk;
 	ictx->save_regs = save_task_regs;
-- 
2.7.4



More information about the CRIU mailing list