pomo

A simple pomodoro timer
Log | Files | Refs | README | LICENSE

commit 44395654d8691c800abf0421f4b8270ace288529
parent b5d373cbb4b780249f18fb2a631592229730a28a
Author: Simon Lieb <simon@e5150.fr>
Date:   Tue, 25 Oct 2016 20:54:16 +0200

Fix signal bursts blocking the counter

As sleep() would only detect a minimum of 1 second of sleeping, using
nanosleep() solves this problem. But we now required to define
POSIX_C_SOURCE >= 199309

Diffstat:
Mconfig.mk | 2+-
Mspt.c | 18++++++++++--------
2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/config.mk b/config.mk @@ -16,7 +16,7 @@ INCS+= `pkg-config --cflags libnotify` LIBS+= `pkg-config --libs libnotify` # flags -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE=199309 CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${DEFS} ${CPPFLAGS} LDFLAGS += -g ${LIBS} diff --git a/spt.c b/spt.c @@ -5,6 +5,7 @@ #include <string.h> #include <unistd.h> #include <signal.h> +#include <time.h> #ifdef NOTIFY #include <libnotify/notify.h> #endif /* NOTIFY */ @@ -112,9 +113,10 @@ usage(void) int main(int argc, char *argv[]) { + struct timespec remaining; struct sigaction sa; sigset_t emptymask; - int i, timecount; + int i; ARGBEGIN { case 'e': @@ -149,17 +151,17 @@ main(int argc, char *argv[]) for (i = 0; ; i = (i + 1) % LEN(timers)) { notify_send(timers[i].cmt); - timecount = 0; - while (timecount < timers[i].tmr) { + remaining.tv_sec = timers[i].tmr; + remaining.tv_nsec = 0; + while (remaining.tv_sec) { if (display) - display_time(timecount); + display_time(remaining.tv_sec); if (suspend) sigsuspend(&emptymask); - else { - sleep(1); - timecount++; - } + else + if (nanosleep(&remaining, &remaining) == 0) + remaining.tv_sec = remaining.tv_nsec = 0; } }