[CRIU] [PATCH v3 1/5] lazy-pages: use abstract UNIX socket
Mike Rapoport
mike.rapoport at gmail.com
Wed Nov 2 16:01:44 PDT 2016
From: Andrei Vagin <avagin at virtuozzo.com>
Replace file-system based UNIX socket name with abstract. This ensures we
won't run into problems with invalid socket names.
v2: fix compilation on arm
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
Acked-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
criu/uffd.c | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/criu/uffd.c b/criu/uffd.c
index 2a9dab4..3d0a446 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -123,26 +123,27 @@ static void lpi_hash_fini(void)
lpi_fini(p);
}
-static int prepare_sock_addr(struct sockaddr_un *saddr)
+static int prepare_sock_addr(struct sockaddr_un *saddr, socklen_t *plen)
{
- char cwd[PATH_MAX];
+ struct stat st;
int len;
- if (!getcwd(cwd, PATH_MAX)) {
- pr_perror("Cannot get CWD\n");
+ if (stat(".", &st) == -1)
return -1;
- }
memset(saddr, 0, sizeof(struct sockaddr_un));
saddr->sun_family = AF_UNIX;
len = snprintf(saddr->sun_path, sizeof(saddr->sun_path),
- "%s/%s", cwd, LAZY_PAGES_SOCK_NAME);
+ "X/%s/%"PRIx64"/%"PRIx64, LAZY_PAGES_SOCK_NAME,
+ st.st_dev, st.st_ino);
if (len >= sizeof(saddr->sun_path)) {
- pr_err("Wrong UNIX socket name: %s/%s\n",
- cwd, LAZY_PAGES_SOCK_NAME);
+ pr_err("Wrong UNIX socket name: %s%"PRIx64"/%"PRIx64"\n",
+ LAZY_PAGES_SOCK_NAME, st.st_dev, st.st_ino);
return -1;
}
+ *plen = SUN_LEN(saddr);
+ saddr->sun_path[0] = 0;
return 0;
}
@@ -253,13 +254,13 @@ err:
int prepare_lazy_pages_socket(void)
{
int fd, new_fd;
- int len;
+ socklen_t len;
struct sockaddr_un sun;
if (!opts.lazy_pages)
return 0;
- if (prepare_sock_addr(&sun))
+ if (prepare_sock_addr(&sun, &len))
return -1;
lazy_sock_mutex = shmalloc(sizeof(*lazy_sock_mutex));
@@ -276,7 +277,6 @@ int prepare_lazy_pages_socket(void)
if (new_fd < 0)
return -1;
- len = offsetof(struct sockaddr_un, sun_path) + strlen(sun.sun_path);
if (connect(new_fd, (struct sockaddr *) &sun, len) < 0) {
pr_perror("connect to %s failed", sun.sun_path);
close(new_fd);
@@ -286,18 +286,15 @@ int prepare_lazy_pages_socket(void)
return 0;
}
-static int server_listen(struct sockaddr_un *saddr)
+static int server_listen(struct sockaddr_un *saddr, int len)
{
int fd;
- int len;
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
return -1;
unlink(saddr->sun_path);
- len = offsetof(struct sockaddr_un, sun_path) + strlen(saddr->sun_path);
-
if (bind(fd, (struct sockaddr *) saddr, len) < 0) {
goto out;
}
@@ -846,11 +843,11 @@ static int prepare_uffds(int epollfd)
socklen_t len;
struct sockaddr_un saddr;
- if (prepare_sock_addr(&saddr))
+ if (prepare_sock_addr(&saddr, &len))
return -1;
pr_debug("Waiting for incoming connections on %s\n", saddr.sun_path);
- if ((listen = server_listen(&saddr)) < 0) {
+ if ((listen = server_listen(&saddr, len)) < 0) {
pr_perror("server_listen error");
return -1;
}
--
1.9.1
More information about the CRIU
mailing list