start: improve devpts fd sending

Closes: #3549. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 49f04965
...@@ -1531,13 +1531,15 @@ static int lxc_setup_devpts(struct lxc_handler *handler) ...@@ -1531,13 +1531,15 @@ static int lxc_setup_devpts(struct lxc_handler *handler)
devpts_fd = openat(-EBADF, "/dev/pts", O_CLOEXEC | O_DIRECTORY | O_PATH | O_NOFOLLOW); devpts_fd = openat(-EBADF, "/dev/pts", O_CLOEXEC | O_DIRECTORY | O_PATH | O_NOFOLLOW);
if (devpts_fd < 0) { if (devpts_fd < 0) {
devpts_fd = -EBADF;
TRACE("Failed to create detached devpts mount"); TRACE("Failed to create detached devpts mount");
ret = lxc_abstract_unix_send_fds(sock, NULL, 0, NULL, 0); ret = lxc_abstract_unix_send_fds(sock, NULL, 0, &devpts_fd, sizeof(int));
} else { } else {
ret = lxc_abstract_unix_send_fds(sock, &devpts_fd, 1, NULL, 0); ret = lxc_abstract_unix_send_fds(sock, &devpts_fd, 1, NULL, 0);
} }
if (ret < 0) if (ret < 0)
return log_error_errno(-1, errno, "Failed to send devpts fd to parent"); return log_error_errno(-1, errno, "Failed to send devpts fd to parent");
TRACE("Sent devpts file descriptor %d to parent", devpts_fd);
/* Remove any pre-existing /dev/ptmx file. */ /* Remove any pre-existing /dev/ptmx file. */
ret = remove("/dev/ptmx"); ret = remove("/dev/ptmx");
......
...@@ -1878,13 +1878,14 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1878,13 +1878,14 @@ static int lxc_spawn(struct lxc_handler *handler)
} }
} }
ret = lxc_abstract_unix_recv_fds(data_sock1, &handler->conf->devpts_fd, 1, NULL, 0); ret = lxc_abstract_unix_recv_fds(data_sock1, &handler->conf->devpts_fd, 1,
&handler->conf->devpts_fd,
sizeof(handler->conf->devpts_fd));
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to receive devpts fd from child"); SYSERROR("Failed to receive devpts fd from child");
goto out_delete_net; goto out_delete_net;
} }
if (ret == 0) TRACE("Received devpts file descriptor %d from child", handler->conf->devpts_fd);
handler->conf->devpts_fd = -EBADF;
/* Now all networks are created, network devices are moved into place, /* Now all networks are created, network devices are moved into place,
* and the correct names and ifindices in the respective namespaces have * and the correct names and ifindices in the respective namespaces have
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment