[CRIU] [PATCH] unix: Add support for restoring unix receive queue for DGRAM sockets

Kirill Tkhai ktkhai at odin.com
Thu Nov 26 02:41:23 PST 2015


Restore a receive queue in cases of:

1)socketpair with closed second end;
2)peer-less "listening" socket, who is a peer for others.

The only hack we use here is the connect with AF_UNSPEC family,
which clears peer of restoring socket. See unix_dgram_connect()
for the details.

This also makes socket_close_data test working.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 sk-unix.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/sk-unix.c b/sk-unix.c
index 91e4263..011739d 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -1133,6 +1133,28 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
 
 		close(sks[1]);
 		sk = sks[0];
+	} else if (ui->ue->type == SOCK_DGRAM && !ui->ue->peer) {
+		struct sockaddr_un addr;
+		int sks[2];
+
+		if (socketpair(PF_UNIX, ui->ue->type, 0, sks) < 0) {
+			pr_perror("Can't create socketpair");
+			return -1;
+		}
+
+		sk = sks[0];
+		addr.sun_family = AF_UNSPEC;
+
+		if (connect(sk, &addr, sizeof(addr.sun_family))) {
+			pr_perror("Can't clear socker peer");
+			return -1;
+		}
+
+		if (restore_sk_queue(sks[1], ui->ue->id)) {
+			pr_perror("Can't restore socket queue");
+			return -1;
+		}
+		close(sks[1]);
 	} else {
 		if (ui->ue->uflags & USK_CALLBACK) {
 			sk = run_plugins(RESTORE_UNIX_SK, ui->ue->ino);



More information about the CRIU mailing list