]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
ttys: ensure container_ttys= env variable is set correctly 4089/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 22 Feb 2022 11:17:23 +0000 (12:17 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 22 Feb 2022 11:20:15 +0000 (12:20 +0100)
Fixes: #4088
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/terminal.c
src/lxc/terminal.h

index e656f63bbd74b8d56a50e5691ca383bbc5879fa0..c1ce717bff7e881ed5073a3ef68547b708d549e0 100644 (file)
@@ -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;
        }
index c5bf8cdfe3c5bc2507ac50dbfdf806b3b77e957f..38ba5c14d01089f9ff0c915eb2cd59de62871922 100644 (file)
@@ -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)
index 45d6a18ccfd42f587a730f90b0b0b2265e459aa9..d8e0f5c115ec88cc46c353692226b6cf364f521a 100644 (file)
@@ -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 {