From 764e27a4ddab3941239bba83fb6e69eeebce5982 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 25 Aug 2013 17:43:20 +1000 Subject: [PATCH] Increase watch interval. watch would only use an interval of up to 4294 seconds and silently change to this limit. The 4294 seconds is 2^32/10^6 or how many microseconds fit into unsigned int. This change increases the limit to 2^32 seconds which is approximately 136 years. This should be ok for now. Anything above the old limit now uses sleep() instead of usleep() which only uses integers (so 9999.123 seconds will be 9999 seconds) This bug was first reported in 2006 and included a patch by Stephen Kratzer. The patch was updated to fit the current source. Bug-Debian: http://bugs.debian.org/720445 References: http://sourceforge.net/mailarchive/message.php?msg_id=4335929 Signed-off-by: Craig Small --- watch.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/watch.c b/watch.c index 07134487..436d2135 100644 --- a/watch.c +++ b/watch.c @@ -35,10 +35,9 @@ #include "xalloc.h" #include #include -#include #include #include -#include +#include #include #include #include @@ -47,7 +46,6 @@ #include #include #include -#include #include #include #ifdef WITH_WATCH8BIT @@ -628,8 +626,8 @@ int main(int argc, char *argv[]) interval = strtod_or_err(optarg, _("failed to parse argument")); if (interval < 0.1) interval = 0.1; - if (interval > ~0u / 1000000) - interval = ~0u / 1000000; + if (interval > UINT_MAX) + interval = UINT_MAX; break; case 'p': precise_timekeeping = 1; @@ -738,7 +736,10 @@ int main(int argc, char *argv[]) if (cur_time < next_loop) usleep(next_loop - cur_time); } else - usleep(interval * 1000000); + if (interval < UINT_MAX / USECS_PER_SEC) + usleep(interval * USECS_PER_SEC); + else + sleep(interval); } endwin();