On Mon, Sep 15, 2025 at 06:34:15PM +0200, Maximilian Immanuel Brandtner wrote:
> Update the terminal size upon SIGWINCH delivery.
>
> Signed-off-by: Maximilian Immanuel Brandtner <[email protected]>
Maximilian, on a related note, could you comment on the revert
of your patch that I posted to lkml? Thanks!
> ---
>
> To be committed with the patch-set: [PATCH v4 00/10] virtio-console: notify
> about the terminal size
>
> v1 -> v2: Move comment regarding patch dependencies to note section
> ---
> chardev/char-pty.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/chardev/char-pty.c b/chardev/char-pty.c
> index 674e9b3f14..802bae9037 100644
> --- a/chardev/char-pty.c
> +++ b/chardev/char-pty.c
> @@ -28,6 +28,7 @@
> #include "io/channel-file.h"
> #include "qemu/sockets.h"
> #include "qemu/error-report.h"
> +#include "qemu/main-loop.h"
> #include "qemu/module.h"
> #include "qemu/option.h"
> #include "qemu/qemu-print.h"
> @@ -35,6 +36,8 @@
> #include "chardev/char-io.h"
> #include "qom/object.h"
>
> +#include <sys/ioctl.h>
> +
> struct PtyChardev {
> Chardev parent;
> QIOChannel *ioc;
> @@ -43,6 +46,8 @@ struct PtyChardev {
> int connected;
> GSource *timer_src;
> char *path;
> +
> + Notifier resize_notifier;
> };
> typedef struct PtyChardev PtyChardev;
>
> @@ -85,6 +90,15 @@ static void pty_chr_rearm_timer(Chardev *chr, int ms)
> g_free(name);
> }
>
> +static void pty_chr_resize(PtyChardev *s)
> +{
> + struct winsize ws;
> +
> + if (ioctl(QIO_CHANNEL_FILE(s->ioc)->fd, TIOCGWINSZ, &ws) != -1) {
> + qemu_chr_resize(CHARDEV(s), ws.ws_col, ws.ws_row);
> + }
> +}
> +
> static void pty_chr_update_read_handler(Chardev *chr)
> {
> PtyChardev *s = PTY_CHARDEV(chr);
> @@ -331,6 +345,12 @@ static int qemu_openpty_raw(int *aslave, char *pty_name)
> return amaster;
> }
>
> +static void term_resize_notify(Notifier *n, void *data)
> +{
> + PtyChardev *s = container_of(n, PtyChardev, resize_notifier);
> + pty_chr_resize(s);
> +}
> +
> static void char_pty_open(Chardev *chr,
> ChardevBackend *backend,
> bool *be_opened,
> @@ -376,6 +396,10 @@ static void char_pty_open(Chardev *chr,
> s->path = g_strdup(path);
> }
> }
> +
> + pty_chr_resize(s);
> + s->resize_notifier.notify = term_resize_notify;
> + sigwinch_add_notifier(&s->resize_notifier);
> }
>
> static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
> --
> 2.50.1