watchdog: Add an info message if the watchdog reset the system
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Sun, 18 Jul 2021 21:51:12 +0000 (23:51 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 25 Jul 2021 12:07:14 +0000 (14:07 +0200)
The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.

To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.
Investigating why a device has rebooted can be difficult, especially if
there's no output (for example during a kernel crash) on the serial
console. Some watchdog drivers can tell us if the watchdog has caused
the system to reboot. The corresponding WDIOF_CARDRESET flag is
documented as: "Card previously reset the CPU".

Add an info message if the watchdog supports the WDIOF_CARDRESET flag
and if the boot status indicates that the watchdog has previously reset
the system.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
watchdog.c

index 9d770b4470a946ec37cc65d5769445ecd544997b..39ae9ff9aa5823ab05c9b1af3e650a11e93cf7d3 100644 (file)
@@ -93,6 +93,35 @@ static int watchdog_set_drv_timeout(void)
        return ioctl(wdt_fd, WDIOC_SETTIMEOUT, &wdt_drv_timeout);
 }
 
+static void watchdog_print_status(void)
+{
+       struct watchdog_info wdt_info;
+       int bootstatus;
+
+       if (wdt_fd < 0)
+               return;
+
+       if (ioctl(wdt_fd, WDIOC_GETSUPPORT, &wdt_info)) {
+               DEBUG(2, "Watchdog GETSUPPORT failed\n");
+               return;
+       }
+
+       if (!(wdt_info.options & WDIOF_CARDRESET)) {
+               DEBUG(2, "Watchdog does not have CARDRESET support\n");
+               return;
+       }
+
+       if (ioctl(wdt_fd, WDIOC_GETBOOTSTATUS, &bootstatus)) {
+               DEBUG(2, "Watchdog GETBOOTSTATUS failed\n");
+               return;
+       }
+
+       if (bootstatus & WDIOF_CARDRESET)
+               LOG("Watchdog has previously reset the system\n");
+       else
+               DEBUG(2, "Watchdog did not previously reset the system\n");
+}
+
 void watchdog_set_magicclose(bool val)
 {
        wdt_magicclose = val;
@@ -170,6 +199,8 @@ void watchdog_init(int preinit)
        watchdog_timeout_cb(&wdt_timeout);
 
        DEBUG(4, "Opened watchdog with timeout %ds\n", watchdog_timeout(0));
+
+       watchdog_print_status();
 }