Skip to content

Commit

Permalink
Fix #149: Invalid calculation of next timer for timer_settime()
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Nilsson <[email protected]>
  • Loading branch information
troglobit committed Jul 22, 2020
1 parent c8142c1 commit 8bbce9a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ static int start(struct timespec *now)
memset(&it, 0, sizeof(it));
it.it_value.tv_sec = next->timeout.tv_sec - now->tv_sec;
it.it_value.tv_nsec = next->timeout.tv_nsec - now->tv_nsec;
timer_settime(timer, 0, &it, NULL);
if (it.it_value.tv_nsec < 0) {
it.it_value.tv_sec -= 1;
it.it_value.tv_nsec = 1000000000 + it.it_value.tv_nsec;
}
if (it.it_value.tv_sec < 0)
it.it_value.tv_sec = 0;

if (timer_settime(timer, 0, &it, NULL))
smclog(LOG_ERR, "Failed starting %d sec period timer, errno %d: %s",
next->timeout.tv_sec - now->tv_sec, errno, strerror(errno));

return 0;
}
Expand Down

0 comments on commit 8bbce9a

Please sign in to comment.