From: Simon Ruderich Date: Thu, 23 Oct 2014 09:32:48 +0000 (+0200) Subject: fix race condition in handle_wall() X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=bcd8ae1311102a644bd6d0dc0774d824169027b5;p=wall-notify%2Fwall-notify.git fix race condition in handle_wall() If a signal occurred before the while loop is reached, it was lost. --- 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;