Skip to content

Commit

Permalink
ttys: ensure container_ttys= env variable is set correctly
Browse files Browse the repository at this point in the history
Fixes: #4088
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 22, 2022
1 parent 96a30fe commit 3b9f84f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lxc/conf.c
Expand Up @@ -1089,17 +1089,20 @@ static int lxc_allocate_ttys(struct lxc_conf *conf)
return -ENOMEM;

for (size_t i = 0; i < conf->ttys.max; i++) {
int pty_nr = -1;
struct lxc_terminal_info *tty = &ttys->tty[i];

ret = lxc_devpts_terminal(conf->devpts_fd, &tty->ptx,
&tty->pty, &pty_nr, false);
&tty->pty, &tty->pty_nr, false);
if (ret < 0) {
conf->ttys.max = i;
return syserror_set(-ENOTTY, "Failed to create tty %zu", i);
}
ret = strnprintf(tty->name, sizeof(tty->name), "pts/%d", tty->pty_nr);
if (ret < 0)
return syserror("Failed to create tty %zu", i);

DEBUG("Created tty with ptx fd %d and pty fd %d and index %d",
tty->ptx, tty->pty, pty_nr);
tty->ptx, tty->pty, tty->pty_nr);
tty->busy = -1;
}

Expand Down Expand Up @@ -1180,6 +1183,7 @@ static int lxc_create_ttys(struct lxc_handler *handler)
SYSERROR("Failed to set \"container_ttys=%s\"", conf->ttys.tty_names);
goto on_error;
}
TRACE("Set \"container_ttys=%s\"", conf->ttys.tty_names);
}

return 0;
Expand Down Expand Up @@ -4163,6 +4167,7 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
for (size_t i = 0; i < ttys_max; i++) {
terminal_info = &info_new->tty[i];
terminal_info->busy = -1;
terminal_info->pty_nr = -1;
terminal_info->ptx = -EBADF;
terminal_info->pty = -EBADF;
}
Expand Down
1 change: 1 addition & 0 deletions src/lxc/terminal.c
Expand Up @@ -1371,6 +1371,7 @@ void lxc_terminal_info_init(struct lxc_terminal_info *terminal)
terminal->ptx = -EBADF;
terminal->pty = -EBADF;
terminal->busy = -1;
terminal->pty_nr = -1;
}

void lxc_terminal_init(struct lxc_terminal *terminal)
Expand Down
3 changes: 3 additions & 0 deletions src/lxc/terminal.h
Expand Up @@ -29,6 +29,9 @@ struct lxc_terminal_info {

/* whether the terminal is currently used */
int busy;

/* the number of the terminal */
int pty_nr;
};

struct lxc_terminal_state {
Expand Down

0 comments on commit 3b9f84f

Please sign in to comment.