[v3,43/55] ns: Install transport fd socket in usernsd

Submitted by Kirill Tkhai on April 10, 2017, 8:22 a.m.

Details

Message ID 149181253092.17342.7869544608671671625.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai April 10, 2017, 8:22 a.m.
In next patches we will need a named socket in usernsd,
to send "set last pid" requests. Create transport socket
for that.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/namespaces.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/namespaces.c b/criu/namespaces.c
index f07860582..3562f9a2a 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -30,6 +30,7 @@ 
 
 #include "protobuf.h"
 #include "util.h"
+#include "util-pie.h"
 #include "images/ns.pb-c.h"
 #include "common/scm.h"
 #include "fdstore.h"
@@ -1509,8 +1510,33 @@  static void unsc_msg_pid_fd(struct unsc_msg *um, pid_t *pid, int *fd)
 
 static int usernsd(int sk)
 {
+	struct sockaddr_un addr;
+	int transport_fd;
+	socklen_t len;
+
 	pr_info("uns: Daemon started\n");
 
+	transport_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+	if (transport_fd < 0) {
+		pr_perror("Can't create transport socket");
+		return -1;
+	}
+
+	addr.sun_family = AF_UNIX;
+	snprintf(addr.sun_path, UNIX_PATH_MAX, "x/criu-usernsd");
+	len = SUN_LEN(&addr);
+	*addr.sun_path = '\0';
+
+	if (bind(transport_fd, (struct sockaddr *)&addr, len) < 0) {
+		pr_perror("Can't bind transport sock");
+		return -1;
+	}
+
+	if (install_service_fd(TRANSPORT_FD_OFF, transport_fd) < 0) {
+		pr_perror("Can't install transport fd\n");
+		return -1;
+	}
+
 	while (1) {
 		struct unsc_msg um;
 		static char msg[MAX_UNSFD_MSG_SIZE];