aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/watchdogd
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2013-03-26 19:43:18 +0000
committerMark Johnston <markj@FreeBSD.org>2013-03-26 19:43:18 +0000
commit8d7ad01f94e40806f616c6da811d08d00054a071 (patch)
tree9ec6d86b0950b1f2e7097e8c9b4d04987813afa5 /usr.sbin/watchdogd
parent7f7fc25b5aa29e7619914bf214df866d82b2c8cd (diff)
downloadsrc-8d7ad01f94e40806f616c6da811d08d00054a071.tar.gz
src-8d7ad01f94e40806f616c6da811d08d00054a071.zip
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)
Notes
Notes: svn path=/head/; revision=248744
Diffstat (limited to 'usr.sbin/watchdogd')
-rw-r--r--usr.sbin/watchdogd/watchdogd.810
-rw-r--r--usr.sbin/watchdogd/watchdogd.c39
2 files changed, 33 insertions, 16 deletions
diff --git a/usr.sbin/watchdogd/watchdogd.8 b/usr.sbin/watchdogd/watchdogd.8
index 3fb61f6c8779..b8a550516437 100644
--- a/usr.sbin/watchdogd/watchdogd.8
+++ b/usr.sbin/watchdogd/watchdogd.8
@@ -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
diff --git a/usr.sbin/watchdogd/watchdogd.c b/usr.sbin/watchdogd/watchdogd.c
index bb923875a69d..e255e07bcc53 100644
--- a/usr.sbin/watchdogd/watchdogd.c
+++ b/usr.sbin/watchdogd/watchdogd.c
@@ -77,7 +77,7 @@ static int is_dry_run = 0; /* do not arm the watchdog, only
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 timespec *tp_start,
}
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;