diff options
author | Andriy Gapon <avg@FreeBSD.org> | 2016-11-10 10:45:12 +0000 |
---|---|---|
committer | Andriy Gapon <avg@FreeBSD.org> | 2016-11-10 10:45:12 +0000 |
commit | a18f280538bce0eff94c36f12382bff0211f1725 (patch) | |
tree | 790ddc576128f9747596b4e6a93aab42e42ffac2 /usr.sbin/watchdogd | |
parent | 46542a426e4e361a5b16723e3ebcc683f7800dbf (diff) | |
download | src-a18f280538bce0eff94c36f12382bff0211f1725.tar.gz src-a18f280538bce0eff94c36f12382bff0211f1725.zip |
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 <olivier@gid0.org>,
Alex Deiter <alex.deiter@gmail.com>
Tested by: Olivier Smedts <olivier@gid0.org>,
Alex Deiter <alex.deiter@gmail.com>
MFC after: 5 days
X-MFC with: r308040
Notes
Notes:
svn path=/head/; revision=308479
Diffstat (limited to 'usr.sbin/watchdogd')
-rw-r--r-- | usr.sbin/watchdogd/watchdogd.c | 16 |
1 files 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", |