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 <csmall@enc.com.au>
This commit is contained in:
Craig Small 2013-08-25 17:43:20 +10:00
parent fd1d13e170
commit 764e27a4dd

13
watch.c
View File

@ -35,10 +35,9 @@
#include "xalloc.h"
#include <ctype.h>
#include <errno.h>
#include <errno.h>
#include <getopt.h>
#include <locale.h>
#include <locale.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -47,7 +46,6 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <termios.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#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();