> Update the terminal size upon SIGWINCH delivery. > > Signed-off-by: Szymon Lukasz <[email protected]> > [Filip: use DECLARE_INSTANCE_CHECKER, qemu_chr_resize_stdio -> > stdio_chr_resize] > Reviewed-by: Daniel P. Berrangé <[email protected]> > Signed-off-by: Filip Hejsek <[email protected]> > Message-ID: <[email protected]> > > diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c > index fe1cbb2d880f..4fc8db212cde 100644 > --- a/chardev/char-stdio.c > +++ b/chardev/char-stdio.c > @@ -34,7 +34,9 @@ > #include "chardev/char-win-stdio.h" > #else > #include <termios.h> > +#include <sys/ioctl.h> > #include "chardev/char-fd.h" > +#include "qemu/main-loop.h" > #endif > > #ifndef _WIN32 > @@ -46,6 +48,14 @@ static bool stdio_in_use; > static bool stdio_allow_signal; > static bool stdio_echo_state; > > +typedef struct { > + FDChardev parent; > + Notifier resize_notifier; > +} StdioChardev; > + > +DECLARE_INSTANCE_CHECKER(StdioChardev, STDIO_CHARDEV, > + TYPE_CHARDEV_STDIO) > + > static void term_exit(void) > { > if (stdio_in_use) { > @@ -85,8 +95,23 @@ static void term_stdio_handler(int sig) > stdio_chr_set_echo(NULL, stdio_echo_state); > } > > +static void stdio_chr_resize(Chardev *chr) > +{ > + struct winsize ws; > + if (ioctl(1, TIOCGWINSZ, &ws) != -1) { > + qemu_chr_resize(chr, ws.ws_col, ws.ws_row); > + } > +} > + > +static void term_resize_notify(Notifier *n, void *data) > +{ > + StdioChardev *s = container_of(n, StdioChardev, resize_notifier); > + stdio_chr_resize(CHARDEV(s)); > +} > + > static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error > **errp) > { > + StdioChardev *s = STDIO_CHARDEV(chr); > ChardevStdio *opts = backend->u.stdio.data; > struct sigaction act; > > @@ -121,6 +146,10 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend > *backend, Error **errp) > stdio_allow_signal = !opts->has_signal || opts->signal; > stdio_chr_set_echo(chr, false); > > + s->resize_notifier.notify = term_resize_notify; > + sigwinch_add_notifier(&s->resize_notifier);
There should be a corresponding sigwinch_remove_notifier() on finalize -- Marc-André Lureau <[email protected]>
