From bcd8ae1311102a644bd6d0dc0774d824169027b5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 23 Oct 2014 11:32:48 +0200 Subject: [PATCH] fix race condition in handle_wall() If a signal occurred before the while loop is reached, it was lost. --- src/wall-notify.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wall-notify.c b/src/wall-notify.c index 95c4d8f..efe5005 100644 --- a/src/wall-notify.c +++ b/src/wall-notify.c @@ -48,8 +48,13 @@ #endif +static sig_atomic_t signaled = 0; + + static void sig_handler(int signal) { (void)signal; + + signaled = 1; } static void setup_signals(void) { struct sigaction action; @@ -332,7 +337,7 @@ static void handle_wall(int fd, char **argv) { ssize_t r; assert(SSIZE_MAX <= SIZE_MAX); - while ((r = read(fd, buffer, sizeof(buffer))) > 0) { + while (!signaled && (r = read(fd, buffer, sizeof(buffer))) > 0) { size_t space; ssize_t r2; -- 2.45.2