mirror of
git://github.com/lxc/lxc
synced 2025-09-01 17:29:30 +00:00
conf: refactor lxc_recv_ttys_from_child()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -1089,7 +1089,7 @@ static int lxc_allocate_ttys(struct lxc_conf *conf)
|
|||||||
|
|
||||||
void lxc_delete_tty(struct lxc_tty_info *ttys)
|
void lxc_delete_tty(struct lxc_tty_info *ttys)
|
||||||
{
|
{
|
||||||
if (!ttys->tty)
|
if (!ttys || !ttys->tty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < ttys->max; i++) {
|
for (int i = 0; i < ttys->max; i++) {
|
||||||
@@ -4059,40 +4059,45 @@ int lxc_idmapped_mounts_parent(struct lxc_handler *handler)
|
|||||||
|
|
||||||
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
|
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
|
||||||
{
|
{
|
||||||
int i;
|
call_cleaner(lxc_delete_tty) struct lxc_tty_info *info_new = &(struct lxc_tty_info){};
|
||||||
struct lxc_terminal_info *tty;
|
|
||||||
int ret = -1;
|
|
||||||
int sock = handler->data_sock[1];
|
int sock = handler->data_sock[1];
|
||||||
struct lxc_conf *conf = handler->conf;
|
struct lxc_conf *conf = handler->conf;
|
||||||
struct lxc_tty_info *ttys = &conf->ttys;
|
struct lxc_tty_info *tty_info = &conf->ttys;
|
||||||
|
size_t ttys_max = tty_info->max;
|
||||||
|
struct lxc_terminal_info *terminal_info;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!conf->ttys.max)
|
if (!ttys_max)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ttys->tty = malloc(sizeof(*ttys->tty) * ttys->max);
|
info_new->tty = malloc(sizeof(*(info_new->tty)) * ttys_max);
|
||||||
if (!ttys->tty)
|
if (!info_new->tty)
|
||||||
return -1;
|
return ret_errno(ENOMEM);
|
||||||
|
|
||||||
for (i = 0; i < conf->ttys.max; i++) {
|
for (int i = 0; i < ttys_max; i++) {
|
||||||
int ttyx = -EBADF, ttyy = -EBADF;
|
terminal_info = &info_new->tty[i];
|
||||||
|
terminal_info->busy = -1;
|
||||||
ret = lxc_abstract_unix_recv_two_fds(sock, &ttyx, &ttyy);
|
terminal_info->ptx = -EBADF;
|
||||||
if (ret < 0)
|
terminal_info->pty = -EBADF;
|
||||||
break;
|
|
||||||
|
|
||||||
tty = &ttys->tty[i];
|
|
||||||
tty->busy = -1;
|
|
||||||
tty->ptx = ttyx;
|
|
||||||
tty->pty = ttyy;
|
|
||||||
TRACE("Received pty with ptx fd %d and pty fd %d from child", tty->ptx, tty->pty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
for (int i = 0; i < ttys_max; i++) {
|
||||||
SYSERROR("Failed to receive %zu ttys from child", ttys->max);
|
int ptx = -EBADF, pty = -EBADF;
|
||||||
else
|
|
||||||
TRACE("Received %zu ttys from child", ttys->max);
|
|
||||||
|
|
||||||
return ret;
|
ret = lxc_abstract_unix_recv_two_fds(sock, &ptx, &pty);
|
||||||
|
if (ret < 0)
|
||||||
|
return syserror("Failed to receive %zu ttys from child", ttys_max);
|
||||||
|
|
||||||
|
terminal_info = &info_new->tty[i];
|
||||||
|
terminal_info->ptx = ptx;
|
||||||
|
terminal_info->pty = pty;
|
||||||
|
TRACE("Received pty with ptx fd %d and pty fd %d from child",
|
||||||
|
terminal_info->ptx, terminal_info->pty);
|
||||||
|
}
|
||||||
|
|
||||||
|
tty_info->tty = move_ptr(info_new->tty);
|
||||||
|
TRACE("Received %zu ttys from child", ttys_max);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxc_send_console_to_parent(struct lxc_handler *handler)
|
static int lxc_send_console_to_parent(struct lxc_handler *handler)
|
||||||
|
Reference in New Issue
Block a user