From 907d0322bb613c85ab0ef326d4436827e1ed07fc Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Mon, 7 Aug 2023 17:27:20 +0200 Subject: [PATCH] libcrun: handle SIGWINCH by resizing terminal_fd When receiving the WINCH signal, crun was using the default signal behavior of passing it through to the child process. A child that cared about the terminal size would then call the TIOCGWINSZ ioctl, but find the size had not changed. This is due to crun not copying the terminal size for its stdin to the child's pty. This changeset handles the WINCH signal by getting crun's terminal size, and setting the child's pty to match. The WINCH signal is not passed through, as the kernel will send it as part of handling the TIOCSWINSZ ioctl. Signed-off-by: Terin Stock --- src/libcrun/container.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcrun/container.c b/src/libcrun/container.c index b9f2afd01..d400428b5 100644 --- a/src/libcrun/container.c +++ b/src/libcrun/container.c @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include #include @@ -1980,6 +1982,7 @@ wait_for_process (struct wait_for_process_args *args, libcrun_error_t *err) while (1) { struct signalfd_siginfo si; + struct winsize ws; ssize_t res; struct epoll_event events[10]; int i, nr_events; @@ -2039,6 +2042,19 @@ wait_for_process (struct wait_for_process_args *args, libcrun_error_t *err) if (last_process) return container_exit_code; } + else if (si.ssi_signo == SIGWINCH) + { + if (UNLIKELY (args->terminal_fd < 0)) + return 0; + + ret = ioctl (0, TIOCGWINSZ, &ws); + if (UNLIKELY (ret < 0)) + return crun_error_wrap (err, "copy terminal size from stdin"); + + ret = ioctl (args->terminal_fd, TIOCSWINSZ, &ws); + if (UNLIKELY (ret < 0)) + return crun_error_wrap (err, "copy terminal size to pty"); + } else { /* Send any other signal to the child process. */