Improved out of range handling of interval specification

pull/47/head
Ashish Kumar Yadav 3 years ago
parent c265691e73
commit 839261d66b

@ -37,8 +37,9 @@ static const char delimiter[] = { ' ', ' ', ' ', DELIMITERENDCHAR };
one newline character at the end)
* pathc - path of the program used for handling clicks on the block */
/* 1 interval = <first entry> seconds, <second entry> nanoseconds */
static const struct timespec interval = { 1, 0 };
/* 1 interval = INTERVALs seconds, INTERVALn nanoseconds */
#define INTERVALs 1
#define INTERVALn 0
static Block blocks[] = {
/* pathu pathc interval signal */

@ -19,6 +19,9 @@
#include "config.h"
_Static_assert(INTERVALs >= 0, "INTERVALs must be greater than or equal to 0");
_Static_assert(INTERVALn >= 0 && INTERVALn <= 999999999, "INTERVALn must be between 0 and 999999999");
static void buttonhandler(int sig, siginfo_t *info, void *ucontext);
static void cleanup();
static void setupsignals();
@ -132,29 +135,19 @@ statusloop()
int i;
struct timespec t;
/* first run */
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
for (Block *block = blocks; block->pathu; block++)
if (block->interval >= 0)
updateblock(block, NILL);
updatestatus();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
t = interval;
while (nanosleep(&t, &t) == -1)
if (errno != EINTR) {
perror("statusloop - nanosleep");
exit(1);
}
/* main loop */
for (i = 1; ; i++) {
updatestatus();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
while (nanosleep(&t, &t) == -1);
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
for (Block *block = blocks; block->pathu; block++)
if (block->interval > 0 && i % block->interval == 0)
updateblock(block, NILL);
updatestatus();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
t = interval;
while (nanosleep(&t, &t) == -1);
}
}

Loading…
Cancel
Save