Skip to content

Commit

Permalink
libcrun: handle SIGWINCH by resizing terminal_fd
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
terinjokes committed Aug 7, 2023
1 parent 81896b2 commit 907d032
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/capability.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <grp.h>
#include <git-version.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 907d032

Please sign in to comment.