From: Ben Harris Date: Sat, 24 Nov 2018 01:57:33 +0000 (+0000) Subject: Simplify code to clear pending SIGALRM. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=d826d1933adeca7b707e28b9f4025147c9d04af8;p=clunk.git Simplify code to clear pending SIGALRM. A simple sigtimedwait() with a timeout of zero will do. No need to muck about with sigpending(). --- diff --git a/clunk.c b/clunk.c index a924bba..4cb8a70 100644 --- 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"); } } }