]> ruderich.org/simon Gitweb - wall-notify/wall-notify.git/commitdiff
fix race condition in handle_wall()
authorSimon Ruderich <simon@ruderich.org>
Thu, 23 Oct 2014 09:32:48 +0000 (11:32 +0200)
committerSimon Ruderich <simon@ruderich.org>
Thu, 23 Oct 2014 09:32:48 +0000 (11:32 +0200)
If a signal occurred before the while loop is reached, it was lost.

src/wall-notify.c

index 95c4d8f8fad53d19534e449aff21b5c078914f30..efe500513f760cff017b631486c6cabfbf6094c2 100644 (file)
 #endif
 
 
 #endif
 
 
+static sig_atomic_t signaled = 0;
+
+
 static void sig_handler(int signal) {
     (void)signal;
 static void sig_handler(int signal) {
     (void)signal;
+
+    signaled = 1;
 }
 static void setup_signals(void) {
     struct sigaction action;
 }
 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);
     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;
 
         size_t space;
         ssize_t r2;