[CRIU] [PATCH 16/19] unix: bind_unix_sk -- Add ability to skip waiters notification

Cyrill Gorcunov gorcunov at gmail.com
Fri Sep 14 17:08:39 MSK 2018


Currently bind_unix_sk is used in two contexts: to bind freshly
created socket pairs and to bind name for sockets which are
to be queued into fdstore (binmounted sockets). For first
case we should notify the waiting side immediately but
in turn bindmount sockets are created early and there might
be the case where peers are not yet even opened and notification
may simply lost or even cause sigsegv since file list is yet
empty. In turn we should defer it until we do a real bindmount
socket opening right after we fetched it from the fdstore.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/sk-unix.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 34e3ff86a5b5..e6a7bb4e0bc9 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -1666,7 +1666,7 @@ static int bind_on_deleted(int sk, struct unix_sk_info *ui)
 	return 0;
 }
 
-static int bind_unix_sk(int sk, struct unix_sk_info *ui)
+static int bind_unix_sk(int sk, struct unix_sk_info *ui, bool notify)
 {
 	struct sockaddr_un addr;
 	int cwd_fd = -1, root_fd = -1, ns_fd = -1;
@@ -1725,8 +1725,8 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
 		goto done;
 	}
 
-	if (ui->ue->state != TCP_LISTEN) {
-		ui->bound = 1;
+	if (notify && ui->ue->state != TCP_LISTEN) {
+		ui->bound = true;
 		wake_connected_sockets(ui);
 	}
 
@@ -1813,10 +1813,10 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui, int *new_fd)
 	}
 	sk[1] = fle_peer->fe->fd;
 
-	if (bind_unix_sk(sk[0], ui))
+	if (bind_unix_sk(sk[0], ui, true))
 		return -1;
 
-	if (bind_unix_sk(sk[1], peer))
+	if (bind_unix_sk(sk[1], peer, true))
 		return -1;
 
 	*new_fd = sk[0];
@@ -2028,8 +2028,11 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
 	}
 
 	if (!(ui->ue->uflags & UNIX_UFLAGS__BINDMOUNT)) {
-		if (bind_unix_sk(sks[0], ui))
+		if (bind_unix_sk(sks[0], ui, true))
 			return -1;
+	} else {
+		ui->bound = true;
+		wake_connected_sockets(ui);
 	}
 
 	if (ui->ue->state == TCP_LISTEN) {
@@ -2389,7 +2392,7 @@ int unix_prepare_bindmount(struct mount_info *mi)
 		goto out;
 	}
 
-	if (bind_unix_sk(sks[0], ui))
+	if (bind_unix_sk(sks[0], ui, false))
 		goto out;
 
 	ui->fdstore_mnt_id[0] = fdstore_add(sks[0]);
-- 
2.17.1



More information about the CRIU mailing list