diff options
author | markj <markj@FreeBSD.org> | 2013-03-26 19:43:18 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2013-03-26 19:43:18 +0000 |
commit | b664987a1a3481b96f38691bf502f77646a0f426 (patch) | |
tree | 9ec6d86b0950b1f2e7097e8c9b4d04987813afa5 /usr.sbin/watchdogd/watchdogd.c | |
parent | 13efc0b1c148f5aa7376868453728df22e08f719 (diff) | |
download | FreeBSD-src-b664987a1a3481b96f38691bf502f77646a0f426.zip FreeBSD-src-b664987a1a3481b96f38691bf502f77646a0f426.tar.gz |
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)
Diffstat (limited to 'usr.sbin/watchdogd/watchdogd.c')
-rw-r--r-- | usr.sbin/watchdogd/watchdogd.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/usr.sbin/watchdogd/watchdogd.c b/usr.sbin/watchdogd/watchdogd.c index bb92387..e255e07 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; |