diff options
author | Joachim Nilsson <troglobit@gmail.com> | 2012-11-04 18:59:18 (GMT) |
---|---|---|
committer | Joachim Nilsson <troglobit@gmail.com> | 2012-11-04 19:30:02 (GMT) |
commit | c5f2432f5e03c401c8f110f086d36803e870f673 (patch) | |
tree | 43890399f173d6dbdafb67d0a23584b992277b84 | |
parent | c0bedbbc7172c3688b2aa6341b8005c425424fb1 (diff) |
Add support for reading reboot cause.1.4
Support for reading WDIOC_GETBOOTSTATUS to /dev/watchdog and saving
this in /var/run/watchdogd.status along with other interesting info.
Also, fix buglet where automatic kick interval could be calculated
to have a period of zero (0) seconds. Minimum 1 sec is now checked.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | watchdogd.c | 52 |
2 files changed, 53 insertions, 1 deletions
@@ -21,7 +21,7 @@ ROOTDIR ?= $(shell pwd) # VERSION ?= $(shell git tag -l | tail -1) -VERSION ?= 1.3 +VERSION ?= 1.4 NAME = watchdogd PKG = $(NAME)-$(VERSION) ARCHIVE = $(PKG).tar.xz diff --git a/watchdogd.c b/watchdogd.c index e075108..b40cda4 100644 --- a/watchdogd.c +++ b/watchdogd.c @@ -92,6 +92,28 @@ static int wdt_get_timeout(void) return count; } +static int wdt_get_bootstatus(void) +{ + int status = 0; + int err; + + if ((err = ioctl(fd, WDIOC_GETBOOTSTATUS, &status))) + status = err; + + if (!err && status) { + if (status & WDIOF_POWERUNDER) + INFO("Reset cause: POWER-ON"); + if (status & WDIOF_FANFAULT) + INFO("Reset cause: FAN-FAULT"); + if (status & WDIOF_OVERHEAT) + INFO("Reset cause: CPU-OVERHEAT"); + if (status & WDIOF_CARDRESET) + INFO("Reset cause: WATCHDOG"); + } + + return status; +} + static void wdt_close(int UNUSED(signo)) { if (fd != -1) { @@ -144,6 +166,30 @@ static void setup_signals(void) sigaction(SIGUSR2, &sa, NULL); } +static void create_bootstatus(int timeout, int interval) +{ + int err; + char *status; + + err = asprintf(&status, "%s%s.status", _PATH_VARRUN, __progname); + if (-1 != err && status) { + FILE *fp; + + fp = fopen(status, "w"); + if (fp) { + int cause = wdt_get_bootstatus(); + + fprintf(fp, "Reset cause : 0x%04x\n", cause >= 0 ? cause : 0); + fprintf(fp, "Timeout (sec) : %d\n", timeout); + fprintf(fp, "Kick interval : %d\n", interval); + + fclose(fp); + } + + free(status); + } +} + static int usage(int status) { printf("Usage: %s [-f] [-w <sec>] [-k <sec>] [-s] [-h|--help]\n" @@ -294,9 +340,15 @@ int main(int argc, char *argv[]) period = WDT_KICK_DEFAULT; else period = real_timeout / 2; + + if (!period) + period = 1; } DEBUG("Watchdog kick interval set to %d sec.", period); + /* Read boot cause from watchdog and save in /var/run/watchdogd.status */ + create_bootstatus(real_timeout, period); + while (1) { int rem; |