chiark / gitweb /
Simplify code to clear pending SIGALRM.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 24 Nov 2018 01:57:33 +0000 (01:57 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 8 Dec 2018 22:30:09 +0000 (22:30 +0000)
A simple sigtimedwait() with a timeout of zero will do.  No need to
muck about with sigpending().

clunk.c

diff --git a/clunk.c b/clunk.c
index a924bbaf48b78898a0fe969af8a3326b813010f8..4cb8a70cd12124a08d72fb92eb74bb2cab5293db 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -277,8 +277,6 @@ run()
        struct timespec const timeout = { .tv_sec = 31, .tv_nsec = 0 };
        struct tm tm;
        int tick;
-       sigset_t pending_signals;
-       int signo;
 
        while (true) {
                if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
@@ -315,14 +313,10 @@ run()
                        if (timer_settime(main_timer, 0,
                                          &its_disarm, NULL) != 0)
                                err(1, "timer_settime (disarm)");
-                       /* Clear any pending SIGALRM. */
-                       if (sigpending(&pending_signals) == -1)
-                               err(1, "sigpending");
-                       if (sigismember(&pending_signals, SIGALRM)) {
-                               errno = sigwait(&timing_signals, &signo);
-                               if (errno != 0)
-                                       err(1, "sigwait");
-                       }
+                       /* Clear any SIGALRM generated before timer disarmed */
+                       if (sigtimedwait(&timing_signals, NULL, &TS_SEC(0))
+                           == -1 && errno != EAGAIN)
+                               err(1, "sigtimedwait");
                }
        }
 }