From 4d1c41e799684d02d4ea45f337bdee1a2d207cb6 Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Fri, 17 May 2024 20:02:22 -0400 Subject: [PATCH] in keyboard demo, retry poll on `EINTR` SIGWINCH may interrupt the `select` call leading to `TB_ERR_POLL` with `errno` of EINTR. retry in this case instead of exiting. --- demo/keyboard.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/demo/keyboard.c b/demo/keyboard.c index 05bce14..d3bea77 100644 --- a/demo/keyboard.c +++ b/demo/keyboard.c @@ -709,7 +709,18 @@ int main(int argc, char **argv) int inputmode = 0; int ctrlxpressed = 0; - while (tb_poll_event(&ev) == TB_OK) { + while (1) { + ret = tb_poll_event(&ev); + + if (ret != TB_OK) { + if (ret == TB_ERR_POLL && tb_last_errno() == EINTR) { + /* poll was interrupted, maybe by a SIGWINCH; try again */ + continue; + } + /* some other error occurred; bail */ + break; + } + switch (ev.type) { case TB_EVENT_KEY: if (ev.key == TB_KEY_CTRL_Q && ctrlxpressed) { -- 2.39.5