1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-05 21:57:27 +03:00

watchdog: configuring a timeout value might not be supported by the HW

In that case we should hanlde this case more gracefully by reusing the
programmed value.

Fixes: #20683
This commit is contained in:
Franck Bui 2021-09-16 18:46:04 +02:00
parent fcbf2c64f5
commit ef1d5f3c5c

View File

@ -40,6 +40,20 @@ static int watchdog_set_enable(bool enable) {
return 0;
}
static int watchdog_get_timeout(void) {
int sec = 0;
assert(watchdog_fd > 0);
if (ioctl(watchdog_fd, WDIOC_GETTIMEOUT, &sec) < 0)
return -errno;
assert(sec > 0);
watchdog_timeout = sec * USEC_PER_SEC;
return 0;
}
static int watchdog_set_timeout(void) {
usec_t t;
int sec;
@ -51,15 +65,11 @@ static int watchdog_set_timeout(void) {
sec = MIN(t, (usec_t) INT_MAX); /* Saturate */
if (ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec) < 0)
return log_warning_errno(errno, "Failed to set timeout to %is, ignoring: %m", sec);
return -errno;
/* Just in case the driver is buggy */
assert(sec > 0);
/* watchdog_timeout stores the timeout used by the HW */
assert(sec > 0);/* buggy driver ? */
watchdog_timeout = sec * USEC_PER_SEC;
log_info("Set hardware watchdog to %s.", FORMAT_TIMESPAN(watchdog_timeout, 0));
return 0;
}
@ -86,13 +96,24 @@ static int update_timeout(void) {
return watchdog_set_enable(false);
r = watchdog_set_timeout();
if (r < 0)
return r;
if (r < 0) {
if (!ERRNO_IS_NOT_SUPPORTED(r))
return log_warning_errno(r, "Failed to set timeout to %s, ignoring: %m",
FORMAT_TIMESPAN(watchdog_timeout, 0));
log_info("Modifying watchdog timeout is not supported, reusing the programmed timeout.");
r = watchdog_get_timeout();
if (r < 0)
return log_warning_errno(errno, "Failed to query watchdog HW timeout, ignoring: %m");
}
r = watchdog_set_enable(true);
if (r < 0)
return r;
log_info("Watchdog running with a timeout of %s.", FORMAT_TIMESPAN(watchdog_timeout, 0));
return watchdog_ping_now();
}