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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent cb5659e1
...@@ -3067,41 +3067,35 @@ static bool verify_start_hooks(struct lxc_conf *conf) ...@@ -3067,41 +3067,35 @@ static bool verify_start_hooks(struct lxc_conf *conf)
static int lxc_send_ttys_to_parent(struct lxc_handler *handler) static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
{ {
int i; int i;
int *ttyfds;
struct lxc_pty_info *pty_info;
struct lxc_conf *conf = handler->conf; 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 sock = handler->data_sock[0];
int ret = -1; int ret = -1;
size_t num_ttyfds = (2 * conf->tty);
ttyfds = malloc(num_ttyfds * sizeof(int)); for (i = 0; i < conf->tty; i++) {
if (!ttyfds) int ttyfds[2];
return -1; struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
for (i = 0; i < num_ttyfds; i++) { ttyfds[0] = pty_info->master;
pty_info = &tty_info->pty_info[i / 2]; ttyfds[1] = pty_info->slave;
ttyfds[i++] = pty_info->slave;
ttyfds[i] = pty_info->master; ret = lxc_abstract_unix_send_fds(sock, ttyfds, 2, NULL, 0);
TRACE("send pty \"%s\" with master fd %d and slave fd %d to " if (ret < 0)
"parent", break;
pty_info->name, pty_info->master, pty_info->slave);
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) 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)); strerror(errno));
else 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[0]);
close(handler->data_sock[1]); close(handler->data_sock[1]);
lxc_delete_tty(tty_info);
for (i = 0; i < num_ttyfds; i++)
close(ttyfds[i]);
free(ttyfds);
return ret; return ret;
} }
......
...@@ -1060,13 +1060,11 @@ out_error: ...@@ -1060,13 +1060,11 @@ out_error:
static int lxc_recv_ttys_from_child(struct lxc_handler *handler) static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
{ {
int i; int i;
int *ttyfds;
struct lxc_pty_info *pty_info; struct lxc_pty_info *pty_info;
int ret = -1; int ret = -1;
int sock = handler->data_sock[1]; int sock = handler->data_sock[1];
struct lxc_conf *conf = handler->conf; struct lxc_conf *conf = handler->conf;
struct lxc_tty_info *tty_info = &conf->tty_info; struct lxc_tty_info *tty_info = &conf->tty_info;
size_t num_ttyfds = (2 * conf->tty);
if (!conf->tty) if (!conf->tty)
return 0; return 0;
...@@ -1075,29 +1073,27 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler) ...@@ -1075,29 +1073,27 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
if (!tty_info->pty_info) if (!tty_info->pty_info)
return -1; return -1;
ttyfds = malloc(num_ttyfds * sizeof(int)); for (i = 0; i < conf->tty; i++) {
if (!ttyfds) int ttyfds[2];
return -1;
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); pty_info = &tty_info->pty_info[i];
for (i = 0; (ret >= 0 && *ttyfds != -1) && (i < num_ttyfds); i++) {
pty_info = &tty_info->pty_info[i / 2];
pty_info->busy = 0; pty_info->busy = 0;
pty_info->slave = ttyfds[i++]; pty_info->master = ttyfds[0];
pty_info->master = ttyfds[i]; pty_info->slave = ttyfds[1];
TRACE("received pty with master fd %d and slave fd %d from " TRACE("Received pty with master fd %d and slave fd %d from "
"parent", pty_info->master, pty_info->slave); "parent", pty_info->master, pty_info->slave);
} }
tty_info->nbtty = conf->tty;
free(ttyfds);
if (ret < 0) 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)); strerror(errno));
else else
TRACE("received %d ttys from child", conf->tty); TRACE("Received %d ttys from child", conf->tty);
tty_info->nbtty = conf->tty;
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment