From 1ded3b11d2eda56f64ec38e09b71214b65ca371a Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Thu, 4 Oct 2018 09:23:14 +0200 Subject: [PATCH] ICS-664: Fix "cu problem" In ttynvt_read(), the "interrupted" signal may be delivered after installing the handler (fuse_req_interrupt_func()) but before calling read(). If this happens the signal intended to be delivered while in the read() function call (SIGUSR2) is handled before the read(), and we may hang indefinitely. --- ttynvt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ttynvt.c b/ttynvt.c index 774eb38..57e9b0b 100644 --- a/ttynvt.c +++ b/ttynvt.c @@ -99,9 +99,12 @@ _PRF2_ static void _log(int prio, const char *fmt, ...) #define DBG2(...) \ if (ttynvt_param.debug > 1) _log(LOG_DEBUG, __VA_ARGS__) +static volatile char _is_interrupted = 0; static void sig_handler(int sig) { + DBG("Interruped, signal = %d\n", sig); + _is_interrupted = 1; } static void set_signal_handler(void) @@ -489,7 +492,9 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off, size = TMP_BUF_SIZE; fuse_req_interrupt_func(req, ttynvt_interrupted, (void *)pthread_self()); - res = read(tty->fds[FD_SLAVE].fd, tty->tmp_buf, size); + res = + _is_interrupted ? -2 : read(tty->fds[FD_SLAVE].fd, tty->tmp_buf, size); + _is_interrupted = 0; fuse_req_interrupt_func(req, NULL, NULL); if (res < 0) {