From 155815ca480f13288b0b303580e6d0af7c145e41 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 4 Aug 2015 07:51:56 +0100 Subject: [PATCH] Maximum ping time should be 120 seconds. Not watchdog_timeout * 2, which for long timeouts means waiting for ages. --- watchdog-test.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/watchdog-test.c b/watchdog-test.c index 77ee178..326160c 100644 --- a/watchdog-test.c +++ b/watchdog-test.c @@ -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)); -- 1.8.3.1