void lxc_delete_tty(struct lxc_tty_info *ttys)
{
- if (!ttys->tty)
+ if (!ttys || !ttys->tty)
return;
for (int i = 0; i < ttys->max; i++) {
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
{
- int i;
- struct lxc_terminal_info *tty;
- int ret = -1;
+ call_cleaner(lxc_delete_tty) struct lxc_tty_info *info_new = &(struct lxc_tty_info){};
int sock = handler->data_sock[1];
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;
- ttys->tty = malloc(sizeof(*ttys->tty) * ttys->max);
- if (!ttys->tty)
- return -1;
+ info_new->tty = malloc(sizeof(*(info_new->tty)) * ttys_max);
+ if (!info_new->tty)
+ return ret_errno(ENOMEM);
- for (i = 0; i < conf->ttys.max; i++) {
- int ttyx = -EBADF, ttyy = -EBADF;
+ for (int i = 0; i < ttys_max; i++) {
+ terminal_info = &info_new->tty[i];
+ terminal_info->busy = -1;
+ terminal_info->ptx = -EBADF;
+ terminal_info->pty = -EBADF;
+ }
- ret = lxc_abstract_unix_recv_two_fds(sock, &ttyx, &ttyy);
+ for (int i = 0; i < ttys_max; i++) {
+ int ptx = -EBADF, pty = -EBADF;
+
+ ret = lxc_abstract_unix_recv_two_fds(sock, &ptx, &pty);
if (ret < 0)
- break;
+ return syserror("Failed to receive %zu ttys from child", ttys_max);
- 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);
+ 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);
}
- if (ret < 0)
- SYSERROR("Failed to receive %zu ttys from child", ttys->max);
- else
- TRACE("Received %zu ttys from child", ttys->max);
-
- return ret;
+ 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)