Maximum ping time should be 120 seconds. master
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 4 Aug 2015 06:51:56 +0000 (07:51 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 4 Aug 2015 06:51:56 +0000 (07:51 +0100)
Not watchdog_timeout * 2, which for long timeouts means waiting
for ages.

watchdog-test.c

index 77ee178..326160c 100644 (file)
@@ -30,6 +30,8 @@
 #define WATCHDOG_DEVICE "/dev/watchdog"
 #define WATCHDOG_TIMEOUT_DEFAULT 30
 
+#define MIN(a,b) ((a)<(b)?(a):(b))
+
 enum { HELP_OPTION = CHAR_MAX + 1 };
 
 static const char *options = "";
@@ -50,6 +52,7 @@ int
 main (int argc, char *argv[])
 {
   int watchdog_timeout = WATCHDOG_TIMEOUT_DEFAULT;
+  int ping_time;
   int fd;
   int timeout;
   char input[256];
@@ -85,6 +88,8 @@ main (int argc, char *argv[])
     }
   }
 
+  ping_time = MIN (watchdog_timeout * 2, 120);
+
   setvbuf (stdout, NULL, _IONBF, 0);
 
   printf ("\n");
@@ -97,7 +102,7 @@ main (int argc, char *argv[])
           watchdog_timeout);
   printf ("(2) I will ping the watchdog for %d seconds.  During this time\n"
           "    the guest should run normally.\n",
-          watchdog_timeout * 2);
+          ping_time);
   printf ("(3) I will stop pinging the watchdog and just count up.  If the\n"
           "    virtual watchdog device is set correctly, then the watchdog\n"
           "    action (eg. reboot) should happen around the %d second mark.\n",
@@ -141,13 +146,13 @@ main (int argc, char *argv[])
   }
 
   printf ("\n");
-  printf ("Pinging the watchdog for %d seconds ...\n", watchdog_timeout*2);
+  printf ("Pinging the watchdog for %d seconds ...\n", ping_time);
   printf ("\n");
 
   time (&start_t);
   for (;;) {
     time (&t);
-    if (t - start_t > watchdog_timeout * 2)
+    if (t - start_t > ping_time)
       break;
     printf ("%d...\n", (int) (t - start_t));