2
0
mirror of git://github.com/lxc/lxc synced 2025-08-31 12:09:35 +00:00

terminal: don't use ttyname_r() for native terminal allocation

Since we can call that function from another mount namespace we need to
do this manually.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner
2021-07-29 15:46:17 +02:00
parent 011d6eaaaa
commit d413c48628

View File

@@ -909,10 +909,12 @@ err:
return -ENODEV;
}
static int lxc_terminal_create_native(const char *name, const char *lxcpath, struct lxc_conf *conf,
static int lxc_terminal_create_native(const char *name, const char *lxcpath,
struct lxc_conf *conf,
struct lxc_terminal *terminal)
{
__do_close int devpts_fd = -EBADF;
__do_close int devpts_fd = -EBADF, fd_pty = -EBADF;
int pty_nr = -1;
int ret;
devpts_fd = lxc_cmd_get_devpts_fd(name, lxcpath);
@@ -949,12 +951,31 @@ static int lxc_terminal_create_native(const char *name, const char *lxcpath, str
goto err;
}
ret = ttyname_r(terminal->pty, terminal->name, sizeof(terminal->name));
ret = ioctl(terminal->ptx, TIOCGPTN, &pty_nr);
if (ret) {
SYSWARN("Failed to retrieve name of terminal pty");
goto err;
}
fd_pty = open_at(devpts_fd, fdstr(pty_nr), PROTECT_OPATH_FILE,
PROTECT_LOOKUP_ABSOLUTE_XDEV, 0);
if (fd_pty < 0) {
SYSWARN("Failed to open terminal pty fd by path %d/%d", devpts_fd, pty_nr);
goto err;
}
if (!same_file_lax(terminal->pty, fd_pty)) {
SYSWARN("Terminal file descriptor changed");
goto err;
}
ret = strnprintf(terminal->name, sizeof(terminal->name), "dev/pts/%d",
pty_nr);
if (ret < 0) {
SYSWARN("Failed to create terminal pty name");
goto err;
}
ret = lxc_terminal_peer_default(terminal);
if (ret < 0) {
SYSWARN("Failed to allocate proxy terminal");