svn commit: r248744 - head/usr.sbin/watchdogd

Mark Johnston markj at FreeBSD.org
Tue Mar 26 19:43:19 UTC 2013


Author: markj
Date: Tue Mar 26 19:43:18 2013
New Revision: 248744
URL: http://svnweb.freebsd.org/changeset/base/248744

Log:
  Invert the meaning of -S (added in r247405) and document its meaning. Also,
  don't carp about the watchdog command taking too long until after the
  watchdog has been patted, and don't carp via warnx(3) unless -S is set
  since syslog(3) already logs to standard error otherwise.
  
  Discussed with:	alfred
  Reviewed by:	alfred
  Approved by:	emaste (co-mentor)

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

Modified: head/usr.sbin/watchdogd/watchdogd.8
==============================================================================
--- head/usr.sbin/watchdogd/watchdogd.8	Tue Mar 26 18:57:25 2013	(r248743)
+++ head/usr.sbin/watchdogd/watchdogd.8	Tue Mar 26 19:43:18 2013	(r248744)
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 2, 2013
+.Dd March 5, 2013
 .Dt WATCHDOGD 8
 .Os
 .Sh NAME
@@ -35,7 +35,7 @@
 .Nd watchdog daemon
 .Sh SYNOPSIS
 .Nm
-.Op Fl dnw
+.Op Fl dnSw
 .Op Fl -debug
 .Op Fl -softtimeout
 .Op Fl -softtimeout-action Ar action
@@ -126,6 +126,12 @@ When this option is specified,
 .Nm
 will not fork into the background at startup.
 .Pp
+.It Fl S
+Do not send a message to the system logger when the watchdog command takes
+longer than expected to execute.
+The default behaviour is to log a warning via the system logger with the
+LOG_DAEMON facility, and to output a warning to standard error.
+.Pp
 .It Fl w
 Complain when the watchdog script takes too long.
 This flag will cause watchdogd to complain when the amount of time to

Modified: head/usr.sbin/watchdogd/watchdogd.c
==============================================================================
--- head/usr.sbin/watchdogd/watchdogd.c	Tue Mar 26 18:57:25 2013	(r248743)
+++ head/usr.sbin/watchdogd/watchdogd.c	Tue Mar 26 19:43:18 2013	(r248744)
@@ -77,7 +77,7 @@ static int is_dry_run = 0;  /* do not ar
 			       report on timing of the watch
 			       program */
 static int do_timedog = 0;
-static int do_syslog = 0;
+static int do_syslog = 1;
 static int fd = -1;
 static int nap = 1;
 static int carp_thresh_seconds = -1;
@@ -125,12 +125,10 @@ main(int argc, char *argv[])
 		
 	parseargs(argc, argv);
 
-	if (do_syslog) {
+	if (do_syslog)
 		openlog("watchdogd", LOG_CONS|LOG_NDELAY|LOG_PERROR,
 		    LOG_DAEMON);
 
-	}
-
 	rtp.type = RTP_PRIO_REALTIME;
 	rtp.prio = 0;
 	if (rtprio(RTP_SET, 0, &rtp) == -1)
@@ -234,8 +232,9 @@ static long
 watchdog_check_dogfunction_time(struct timespec *tp_start,
     struct timespec *tp_end)
 {
-	struct timeval tv_start, tv_end, tv;
+	struct timeval tv_start, tv_end, tv_now, tv;
 	const char *cmd_prefix, *cmd;
+	struct timespec tp_now;
 	int sec;
 
 	if (!do_timedog)
@@ -257,16 +256,28 @@ watchdog_check_dogfunction_time(struct t
 	}
 	if (do_syslog)
 		syslog(LOG_CRIT, "%s: '%s' took too long: "
-		    "%d.%06ld seconds >= %d seconds threshhold",
+		    "%d.%06ld seconds >= %d seconds threshold",
 		    cmd_prefix, cmd, sec, (long)tv.tv_usec,
 		    carp_thresh_seconds);
-	warnx("%s: '%s' took too long: "
-	    "%d.%06ld seconds >= %d seconds threshhold",
-	    cmd_prefix, cmd, sec, (long)tv.tv_usec, carp_thresh_seconds);
+	else
+		warnx("%s: '%s' took too long: "
+		    "%d.%06ld seconds >= %d seconds threshold",
+		    cmd_prefix, cmd, sec, (long)tv.tv_usec,
+		    carp_thresh_seconds);
+
+	/*
+	 * Adjust the sleep interval again in case syslog(3) took a non-trivial
+	 * amount of time to run.
+	 */
+	if (watchdog_getuptime(&tp_now))
+		return (sec);
+	TIMESPEC_TO_TIMEVAL(&tv_now, &tp_now);
+	timersub(&tv_now, &tv_start, &tv);
+	sec = tv.tv_sec;
+
 	return (sec);
 }
 
-
 /*
  * Main program loop which is iterated every second.
  */
@@ -298,10 +309,10 @@ watchdog_loop(void)
 			goto try_end;
 		}
 
-		waited = watchdog_check_dogfunction_time(&ts_start, &ts_end);
-
 		if (failed == 0)
 			watchdog_patpat(timeout|WD_ACTIVE);
+
+		waited = watchdog_check_dogfunction_time(&ts_start, &ts_end);
 		if (nap - waited > 0)
 			sleep(nap - waited);
 
@@ -404,7 +415,7 @@ usage(void)
 {
 	if (is_daemon)
 		fprintf(stderr, "usage:\n"
-"  watchdogd [-dnw] [-e cmd] [-I file] [-s sleep] [-t timeout]\n"
+"  watchdogd [-dnSw] [-e cmd] [-I file] [-s sleep] [-t timeout]\n"
 "            [-T script_timeout]\n"
 "            [--debug]\n"
 "            [--pretimeout seconds] [-pretimeout-action action]\n"
@@ -551,7 +562,7 @@ parseargs(int argc, char *argv[])
 			nap = fetchtimeout(c, NULL, optarg);
 			break;
 		case 'S':
-			do_syslog = 1;
+			do_syslog = 0;
 			break;
 		case 't':
 			p = NULL;


More information about the svn-src-all mailing list