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
This commit is contained in:
Andriy Gapon 2016-11-10 10:45:12 +00:00
parent 46542a426e
commit a18f280538
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=308479

View file

@ -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",