]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: send ttys in batches of 2
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 3 Sep 2017 23:27:04 +0000 (01:27 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Sep 2017 16:38:01 +0000 (18:38 +0200)
I thought we could send all ttys at once but this limits the number of ttys
users can use because of iovec_len restrictions. So let's sent them in batches
of 2.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/start.c

index f9c61e1e46114d2c321a1455109ef3fee690c885..0328d1759fe42c9106e4ad6f4a3af5470dbe5897 100644 (file)
@@ -3006,41 +3006,35 @@ static bool verify_start_hooks(struct lxc_conf *conf)
 static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
 {
        int i;
-       int *ttyfds;
-       struct lxc_pty_info *pty_info;
        struct lxc_conf *conf = handler->conf;
-       const struct lxc_tty_info *tty_info = &conf->tty_info;
+       struct lxc_tty_info *tty_info = &conf->tty_info;
        int sock = handler->data_sock[0];
        int ret = -1;
-       size_t num_ttyfds = (2 * conf->tty);
 
-       ttyfds = malloc(num_ttyfds * sizeof(int));
-       if (!ttyfds)
-               return -1;
+       for (i = 0; i < conf->tty; i++) {
+               int ttyfds[2];
+               struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
 
-       for (i = 0; i < num_ttyfds; i++) {
-               pty_info = &tty_info->pty_info[i / 2];
-               ttyfds[i++] = pty_info->slave;
-               ttyfds[i] = pty_info->master;
-               TRACE("send pty \"%s\" with master fd %d and slave fd %d to "
-                     "parent",
-                     pty_info->name, pty_info->master, pty_info->slave);
+               ttyfds[0] = pty_info->master;
+               ttyfds[1] = pty_info->slave;
+
+               ret = lxc_abstract_unix_send_fds(sock, ttyfds, 2, NULL, 0);
+               if (ret < 0)
+                       break;
+
+               TRACE("Send pty \"%s\" with master fd %d and slave fd %d to "
+                     "parent", pty_info->name, pty_info->master, pty_info->slave);
        }
 
-       ret = lxc_abstract_unix_send_fds(sock, ttyfds, num_ttyfds, NULL, 0);
        if (ret < 0)
-               ERROR("failed to send %d ttys to parent: %s", conf->tty,
+               ERROR("Failed to send %d ttys to parent: %s", conf->tty,
                      strerror(errno));
        else
-               TRACE("sent %d ttys to parent", conf->tty);
+               TRACE("Sent %d ttys to parent", conf->tty);
 
        close(handler->data_sock[0]);
        close(handler->data_sock[1]);
-
-       for (i = 0; i < num_ttyfds; i++)
-               close(ttyfds[i]);
-
-       free(ttyfds);
+       lxc_delete_tty(tty_info);
 
        return ret;
 }
index db617217748b3db2b52cdf7457c8a4ad8010170b..b74317185e385f18dd2d6b95ba2d4cafd2f8b63e 100644 (file)
@@ -1125,13 +1125,11 @@ out_error:
 static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
 {
        int i;
-       int *ttyfds;
        struct lxc_pty_info *pty_info;
        int ret = -1;
        int sock = handler->data_sock[1];
        struct lxc_conf *conf = handler->conf;
        struct lxc_tty_info *tty_info = &conf->tty_info;
-       size_t num_ttyfds = (2 * conf->tty);
 
        if (!conf->tty)
                return 0;
@@ -1140,29 +1138,27 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
        if (!tty_info->pty_info)
                return -1;
 
-       ttyfds = malloc(num_ttyfds * sizeof(int));
-       if (!ttyfds)
-               return -1;
+       for (i = 0; i < conf->tty; i++) {
+               int ttyfds[2];
+
+               ret = lxc_abstract_unix_recv_fds(sock, ttyfds, 2, NULL, 0);
+               if (ret < 0)
+                       break;
 
-       ret = lxc_abstract_unix_recv_fds(sock, ttyfds, num_ttyfds, NULL, 0);
-       for (i = 0; (ret >= 0 && *ttyfds != -1) && (i < num_ttyfds); i++) {
-               pty_info = &tty_info->pty_info[i / 2];
+               pty_info = &tty_info->pty_info[i];
                pty_info->busy = 0;
-               pty_info->slave = ttyfds[i++];
-               pty_info->master = ttyfds[i];
-               TRACE("received pty with master fd %d and slave fd %d from "
+               pty_info->master = ttyfds[0];
+               pty_info->slave = ttyfds[1];
+               TRACE("Received pty with master fd %d and slave fd %d from "
                      "parent", pty_info->master, pty_info->slave);
        }
-
-       tty_info->nbtty = conf->tty;
-
-       free(ttyfds);
-
        if (ret < 0)
-               ERROR("failed to receive %d ttys from child: %s", conf->tty,
+               ERROR("Failed to receive %d ttys from child: %s", conf->tty,
                      strerror(errno));
        else
-               TRACE("received %d ttys from child", conf->tty);
+               TRACE("Received %d ttys from child", conf->tty);
+
+       tty_info->nbtty = conf->tty;
 
        return ret;
 }