Skip to content

Commit fc9d817

Browse files
committed
fix(exec): set initial console size before nsenter exec
The child's slave.set_size({}) after setsid was a no-op (/dev/tty == slave, reads 0x0 writes 0x0) so the pty stayed at 0x0 until the first SIGWINCH. Drop it and only set size when consoleSize is given. On the parent side, after receiving the master fd, resize it from the host terminal before attaching (unless consoleSize was set). Accept the small race window: the parent's single ioctl lands within the child's send_fd→execvpe window in practice. Signed-off-by: Yuming He <ComixHe1895@outlook.com>
1 parent 8cf650c commit fc9d817

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/linyaps_box/container_ref.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ auto linyaps_box::container_ref::exec(exec_container_option option) -> int
6969
auto [master, slave] = create_pty_pair();
7070

7171
slave.setup_stdio();
72-
slave.set_size({ });
72+
if (option.proc.console_size) {
73+
slave.set_size({ option.proc.console_size->height,
74+
option.proc.console_size->width, 0, 0 });
75+
}
7376

7477
option.console_socket->send_fd(std::move(master).take());
7578
option.console_socket.reset();
@@ -147,10 +150,8 @@ auto linyaps_box::container_ref::exec(exec_container_option option) -> int
147150
}
148151
});
149152

150-
[&recv_socketpair, &monitor, &in, &out, &changed]() {
151-
if (!recv_socketpair) {
152-
return;
153-
}
153+
if (recv_socketpair) {
154+
monitor.acquire_host_tty(in, out);
154155

155156
LINYAPS_BOX_DEBUG() << "Container requires a terminal";
156157

@@ -159,12 +160,16 @@ auto linyaps_box::container_ref::exec(exec_container_option option) -> int
159160

160161
recv_socketpair->release();
161162

163+
if (!option.proc.console_size) {
164+
master.resize(monitor.host_tty_size());
165+
}
166+
162167
in.set_nonblock(true);
163168
out.set_nonblock(true);
164169
changed = true;
165170

166-
monitor.enable_io_forwarding(std::move(master), in, out);
167-
}();
171+
monitor.attach_terminal(std::move(master), in, out);
172+
}
168173

169174
return monitor.wait_container_exit();
170175
}

0 commit comments

Comments
 (0)