From: Christian Brauner Date: Tue, 22 Feb 2022 11:17:23 +0000 (+0100) Subject: ttys: ensure container_ttys= env variable is set correctly X-Git-Tag: lxc-5.0.0~30^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4089%2Fhead;p=thirdparty%2Flxc.git ttys: ensure container_ttys= env variable is set correctly Fixes: #4088 Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index e656f63bb..c1ce717bf 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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; } @@ -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; @@ -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; } diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index c5bf8cdfe..38ba5c14d 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -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) diff --git a/src/lxc/terminal.h b/src/lxc/terminal.h index 45d6a18cc..d8e0f5c11 100644 --- a/src/lxc/terminal.h +++ b/src/lxc/terminal.h @@ -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 {