From fbfe5c8208fd8304ee74b2e297585c64a0d6bd81 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 19 Oct 2020 11:38:17 +0200 Subject: [PATCH] start: improve devpts fd sending Closes: #3549. Signed-off-by: Christian Brauner --- src/lxc/conf.c | 4 +++- src/lxc/start.c | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 5962009e3..b8058ffdc 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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); if (devpts_fd < 0) { + devpts_fd = -EBADF; 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 { ret = lxc_abstract_unix_send_fds(sock, &devpts_fd, 1, NULL, 0); } if (ret < 0) 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. */ ret = remove("/dev/ptmx"); diff --git a/src/lxc/start.c b/src/lxc/start.c index 322debf00..7b29d4083 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1953,13 +1953,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) { SYSERROR("Failed to receive devpts fd from child"); goto out_delete_net; } - if (ret == 0) - handler->conf->devpts_fd = -EBADF; + TRACE("Received devpts file descriptor %d from child", handler->conf->devpts_fd); /* Now all networks are created, network devices are moved into place, * and the correct names and ifindices in the respective namespaces have -- 2.47.2