diff options
| author | WormHeamer | 2025-11-08 21:20:54 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-11-08 21:20:54 -0500 |
| commit | abfc9d7655f0b52a0ffeebf456dddfc205c7349b (patch) | |
| tree | 8f3ad9f257e50141e3340d1960cd5590988a9a34 | |
| parent | c27b23a411369febfaa66ae67260b4f67b0b5b17 (diff) | |
use sigprocmask() to prevent poll() from hanging on window resize
| -rw-r--r-- | vui.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 20250918 + #include <sys/ioctl.h> #include <stdlib.h> @@ -208,7 +210,8 @@ void vui_curs_pos(int x, int y) { /* TODO: use something better than signal() */ /* does sigaction allow for a context pointer? */ -static void on_resized(int _) { +static void on_resized(int signo) { + (void)signo; adjust_win_size(); if (win.redraw_fn) { win.redraw_fn(win.redraw_ctx); @@ -243,7 +246,7 @@ void vui_init(void) { win.redraw_all = 1; adjust_win_size(); - signal(SIGWINCH, on_resized); + sigaction(SIGWINCH, &(struct sigaction) { .sa_handler = on_resized }, NULL); } @@ -676,7 +679,13 @@ int vui_printf(int x, int y, const char *fmt, ...) { } int vui_wait_for_input(int ms) { - return poll(&(struct pollfd) { .fd = STDIN_FILENO, .events = POLLIN }, 1, ms); + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGWINCH); + sigprocmask(SIG_BLOCK, &set, NULL); + int r = poll(&(struct pollfd) { .fd = STDIN_FILENO, .events = POLLIN }, 1, ms); + sigprocmask(SIG_UNBLOCK, &set, NULL); + return r; } int vui_has_input(void) { |
