[CRIU] [PATCH]v2 fix data loss when dumping semi-closed unix stream connection.

Ruslan Kuprieiev kupruser at gmail.com
Mon Aug 26 18:11:58 EDT 2013


Hi!

This patch fixes running into loop and data loss, when dumping 
semi-closed unix stream connection.

patchv2 has error check, that was missed in v1.
-------------- next part --------------
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>

diff --git a/sk-queue.c b/sk-queue.c
index 3624258..5896e97 100644
--- a/sk-queue.c
+++ b/sk-queue.c
@@ -127,7 +127,13 @@ int dump_sk_queue(int sock_fd, int sock_id)
 		};
 
 		ret = pe.length = recvmsg(sock_fd, &msg, MSG_DONTWAIT | MSG_PEEK);
-		if (ret < 0) {
+		if (!ret)
+			/*
+			 * It means, that peer has performed an
+			 * orderly shutdown, so we're done.
+			 */
+			break;
+		else if (ret < 0) {
 			if (errno == EAGAIN)
 				break; /* we're done */
 			pr_perror("recvmsg fail: error");
diff --git a/sk-unix.c b/sk-unix.c
index 177bb8b..cf024a5 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -737,6 +737,15 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
 			return -1;
 		}
 
+		/*
+		 * Restore queue at the one end,
+		 * before closing the second one.
+		 */
+		if (restore_sk_queue(sks[1], ui->ue->id)) {
+			pr_perror("Can't restore socket queue");
+			return -1;
+		}
+
 		close(sks[1]);
 		sk = sks[0];
 	} else {


More information about the CRIU mailing list