From: Christian Brauner Date: Sun, 3 Sep 2017 23:27:04 +0000 (+0200) Subject: conf: send ttys in batches of 2 X-Git-Tag: lxc-2.0.9~48^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6069a230e912ef72c4d8ce0d5c5705fcf883404a;p=thirdparty%2Flxc.git conf: send ttys in batches of 2 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 --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index f9c61e1e4..0328d1759 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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; } diff --git a/src/lxc/start.c b/src/lxc/start.c index db6172177..b74317185 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -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; }