From a18f280538bce0eff94c36f12382bff0211f1725 Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Thu, 10 Nov 2016 10:45:12 +0000 Subject: [PATCH] fix a watchdogd regression introduced in r308040 The code assumed that 'timeout' and 'timeout_sec' are in sync which they weren't if no '-t' option was passed to watchdogd. Reported by: Olivier Smedts , Alex Deiter Tested by: Olivier Smedts , Alex Deiter MFC after: 5 days X-MFC with: r308040 --- usr.sbin/watchdogd/watchdogd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/usr.sbin/watchdogd/watchdogd.c b/usr.sbin/watchdogd/watchdogd.c index 9ed9de31683d..1271bbfe35dc 100644 --- a/usr.sbin/watchdogd/watchdogd.c +++ b/usr.sbin/watchdogd/watchdogd.c @@ -685,10 +685,15 @@ seconds_to_pow2ns(int seconds) static void parseargs(int argc, char *argv[]) { + struct timespec ts; int longindex; int c; const char *lopt; + /* Get the default value of timeout_sec from the default timeout. */ + pow2ns_to_ts(timeout, &ts); + timeout_sec = ts.tv_sec; + /* * if we end with a 'd' aka 'watchdogd' then we are the daemon program, * otherwise run as a command line utility. @@ -731,9 +736,9 @@ parseargs(int argc, char *argv[]) case 't': timeout_sec = atoi(optarg); timeout = parse_timeout_to_pow2ns(c, NULL, optarg); - if (debugging) - printf("Timeout is 2^%d nanoseconds\n", - timeout); + if (debugging) + printf("Timeout is 2^%d nanoseconds\n", + timeout); break; case 'T': carp_thresh_seconds = @@ -782,10 +787,7 @@ parseargs(int argc, char *argv[]) if (is_daemon && timeout < WD_TO_1SEC) errx(EX_USAGE, "-t argument is less than one second."); if (pretimeout_set) { - struct timespec ts; - - pow2ns_to_ts(timeout, &ts); - if (pretimeout >= (uintmax_t)ts.tv_sec) { + if (pretimeout >= timeout_sec) { errx(EX_USAGE, "pretimeout (%d) >= timeout (%d -> %ld)\n" "see manual section TIMEOUT RESOLUTION",