[CRIU] [PATCH 1/4] page-server: assign opts.ps_port to sin_port in autobind case

Ruslan Kuprieiev kupruser at gmail.com
Wed Sep 17 17:51:03 PDT 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 page-xfer.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/page-xfer.c b/page-xfer.c
index 3aefb61..5bd21bb 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -258,6 +258,7 @@ int cr_page_server(bool daemon_mode, int cfd)
 {
 	int sk = -1, ask = -1, ret;
 	struct sockaddr_in saddr, caddr;
+	socklen_t slen = sizeof(saddr);
 	socklen_t clen = sizeof(caddr);
 
 	up_page_ids_base();
@@ -280,7 +281,7 @@ int cr_page_server(bool daemon_mode, int cfd)
 	if (get_sockaddr_in(&saddr))
 		goto out;
 
-	if (bind(sk, (struct sockaddr *)&saddr, sizeof(saddr))) {
+	if (bind(sk, (struct sockaddr *)&saddr, slen)) {
 		pr_perror("Can't bind page server");
 		goto out;
 	}
@@ -290,6 +291,17 @@ int cr_page_server(bool daemon_mode, int cfd)
 		goto out;
 	}
 
+	/* Get socket port in case of autobind */
+	if (opts.ps_port == 0) {
+		if (getsockname(sk, (struct sockaddr *)&saddr, &slen)) {
+			pr_perror("Can't get page server name");
+			goto out;
+		}
+
+		opts.ps_port = ntohs(saddr.sin_port);
+		pr_info("Using %u port\n", opts.ps_port);
+	}
+
 no_server:
 	if (daemon_mode) {
 		ret = cr_daemon(1, 0, &ask, cfd);
-- 
1.9.3



More information about the CRIU mailing list