]> granicus.if.org Git - procps-ng/commitdiff
Increase watch interval.
authorCraig Small <csmall@enc.com.au>
Sun, 25 Aug 2013 07:43:20 +0000 (17:43 +1000)
committerCraig Small <csmall@enc.com.au>
Sun, 25 Aug 2013 07:43:20 +0000 (17:43 +1000)
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>
watch.c

diff --git a/watch.c b/watch.c
index 0713448790eecf9246541bf6f20d3f81d1ab443e..436d2135ba1528abf4ed8321f41c58777b2a49d0 100644 (file)
--- a/watch.c
+++ b/watch.c
 #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();