[CRIU] [PATCH 5/9] parasite: move code about creating control sockets in a separate func

Andrey Vagin avagin at openvz.org
Fri Jun 21 00:01:11 EDT 2013


It will be used in a few places

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 parasite-syscall.c | 51 +++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/parasite-syscall.c b/parasite-syscall.c
index 8aed5ee..bf5a1a9 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -369,18 +369,13 @@ static int parasite_set_logfd(struct parasite_ctl *ctl, pid_t pid)
 	return 0;
 }
 
-static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
-{
-	static int ssock = -1;
-
-	struct parasite_init_args *args;
-	int sock;
-
-	args = parasite_args(ctl, struct parasite_init_args);
+static int ssock = -1;
 
+static int prepare_tsock(struct parasite_ctl *ctl, pid_t pid,
+				struct parasite_init_args *args)
+{
 	pr_info("Putting tsock into pid %d\n", pid);
 	args->h_addr_len = gen_parasite_saddr(&args->h_addr, getpid());
-	args->sigframe = ctl->rsigframe;
 
 	if (ssock == -1) {
 		int rst = -1;
@@ -412,6 +407,37 @@ static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
 		}
 	}
 
+	return 0;
+err:
+	close_safe(&ssock);
+	return -1;
+}
+
+static int accept_tsock()
+{
+	int sock;
+
+	sock = accept(ssock, NULL, 0);
+	if (sock < 0) {
+		pr_perror("Can't accept connection to the transport socket");
+		close_safe(&ssock);
+	}
+
+	return sock;
+}
+
+static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
+{
+	struct parasite_init_args *args;
+	int sock;
+
+	args = parasite_args(ctl, struct parasite_init_args);
+
+	args->sigframe = ctl->rsigframe;
+
+	if (prepare_tsock(ctl, pid, args))
+		goto err;
+
 	if (parasite_execute_trap(PARASITE_CMD_INIT, ctl) < 0) {
 		pr_err("Can't init parasite\n");
 		goto err;
@@ -420,16 +446,13 @@ static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
 	ctl->sig_blocked = args->sig_blocked;
 	ctl->use_sig_blocked = true;
 
-	sock = accept(ssock, NULL, 0);
-	if (sock < 0) {
-		pr_perror("Can't accept connection to the transport socket");
+	sock = accept_tsock();
+	if (sock < 0)
 		goto err;
-	}
 
 	ctl->tsock = sock;
 	return 0;
 err:
-	close_safe(&ssock);
 	return -1;
 }
 
-- 
1.8.2.1



More information about the CRIU mailing list