[CRIU] [PATCH] dump: a trasport socket should be SOCK_STREAM

Andrey Vagin avagin at openvz.org
Thu May 30 08:57:54 EDT 2013


because we want to know when one of the sides closed its point.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/parasite.h |  3 ---
 parasite-syscall.c | 36 ++++++++++++++----------------------
 pie/parasite.c     |  6 +-----
 3 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/include/parasite.h b/include/parasite.h
index 0e5720f..3dd42a7 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -66,9 +66,6 @@ struct parasite_init_args {
 	int			h_addr_len;
 	struct sockaddr_un	h_addr;
 
-	int			p_addr_len;
-	struct sockaddr_un	p_addr;
-
 	k_rtsigset_t		sig_blocked;
 
 	struct rt_sigframe	*sigframe;
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 258be82..192d18a 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -376,17 +376,18 @@ static int parasite_set_logfd(struct parasite_ctl *ctl, pid_t pid)
 
 static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
 {
+	static int ssock = -1;
+
 	struct parasite_init_args *args;
-	static int sock = -1;
+	int sock;
 
 	args = parasite_args(ctl, struct parasite_init_args);
 
 	pr_info("Putting tsock into pid %d\n", pid);
 	args->h_addr_len = gen_parasite_saddr(&args->h_addr, getpid());
-	args->p_addr_len = gen_parasite_saddr(&args->p_addr, pid);
 	args->sigframe = ctl->rsigframe;
 
-	if (sock == -1) {
+	if (ssock == -1) {
 		int rst = -1;
 
 		if (current_ns_mask & CLONE_NEWNET) {
@@ -396,32 +397,22 @@ static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
 				return -1;
 		}
 
-		sock = socket(PF_UNIX, SOCK_DGRAM, 0);
-		if (sock < 0)
+		ssock = socket(PF_UNIX, SOCK_STREAM, 0);
+		if (ssock < 0)
 			pr_perror("Can't create socket");
 
 		if (rst > 0 && restore_ns(rst, &net_ns_desc) < 0)
 			return -1;
-		if (sock < 0)
+		if (ssock < 0)
 			return -1;
 
-		if (bind(sock, (struct sockaddr *)&args->h_addr, args->h_addr_len) < 0) {
+		if (bind(ssock, (struct sockaddr *)&args->h_addr, args->h_addr_len) < 0) {
 			pr_perror("Can't bind socket");
 			goto err;
 		}
 
-	} else {
-		struct sockaddr addr = { .sa_family = AF_UNSPEC, };
-
-		/*
-		 * When the peer of a dgram socket dies the original socket
-		 * remains in connected state, thus denying any connections
-		 * from "other" sources. Unconnect the socket by hands thus
-		 * allowing for parasite to connect back.
-		 */
-
-		if (connect(sock, &addr, sizeof(addr)) < 0) {
-			pr_perror("Can't unconnect");
+		if (listen(ssock, 1)) {
+			pr_perror("Can't listen on transport socket");
 			goto err;
 		}
 	}
@@ -434,15 +425,16 @@ 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;
 
-	if (connect(sock, (struct sockaddr *)&args->p_addr, args->p_addr_len) < 0) {
-		pr_perror("Can't connect a transport socket");
+	sock = accept(ssock, NULL, 0);
+	if (sock < 0) {
+		pr_perror("Can't accept connection to the transport socket");
 		goto err;
 	}
 
 	ctl->tsock = sock;
 	return 0;
 err:
-	close_safe(&sock);
+	close_safe(&ssock);
 	return -1;
 }
 
diff --git a/pie/parasite.c b/pie/parasite.c
index e6ee8a2..f4a8f77 100644
--- a/pie/parasite.c
+++ b/pie/parasite.c
@@ -236,14 +236,10 @@ static int init(struct parasite_init_args *args)
 	if (ret < 0)
 		return ret;
 
-	tsock = sys_socket(PF_UNIX, SOCK_DGRAM, 0);
+	tsock = sys_socket(PF_UNIX, SOCK_STREAM, 0);
 	if (tsock < 0)
 		return tsock;
 
-	ret = sys_bind(tsock, (struct sockaddr *) &args->p_addr, args->p_addr_len);
-	if (ret < 0)
-		return ret;
-
 	ret = sys_connect(tsock, (struct sockaddr *)&args->h_addr, args->h_addr_len);
 	if (ret < 0)
 		return ret;
-- 
1.8.2



More information about the CRIU mailing list