From 568004d4834535c81ffb627457dff3081ce67f46 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 24 Jun 2014 16:23:13 +0200 Subject: [PATCH] timer: Complain if a timer is set more than 5 seconds from now Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/timer.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/timer.c b/src/timer.c index f5461858..3076bb7a 100644 --- a/src/timer.c +++ b/src/timer.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -65,6 +66,22 @@ libinput_timer_arm_timer_fd(struct libinput *libinput) void libinput_timer_set(struct libinput_timer *timer, uint64_t expire) { +#ifndef NDEBUG + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + uint64_t now = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000; + if (abs(expire - now) > 5000) + log_bug_libinput(timer->libinput, + "timer offset more than 5s, now %" + PRIu64 " expire %" PRIu64 "\n", + now, expire); + } else { + log_error(timer->libinput, + "clock_gettime error: %s\n", strerror(errno)); + } +#endif + assert(expire); if (!timer->expire) -- 2.34.1