Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Nov 2016 10:45:12 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r308479 - head/usr.sbin/watchdogd
Message-ID:  <201611101045.uAAAjCvp098416@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Thu Nov 10 10:45:12 2016
New Revision: 308479
URL: https://svnweb.freebsd.org/changeset/base/308479

Log:
  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

Modified:
  head/usr.sbin/watchdogd/watchdogd.c

Modified: head/usr.sbin/watchdogd/watchdogd.c
==============================================================================
--- head/usr.sbin/watchdogd/watchdogd.c	Thu Nov 10 07:05:41 2016	(r308478)
+++ head/usr.sbin/watchdogd/watchdogd.c	Thu Nov 10 10:45:12 2016	(r308479)
@@ -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",



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201611101045.uAAAjCvp098416>