1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-13 12:58:20 +03:00

Merge pull request #20751 from poettering/watchdog-tweaklet

two minor watchdog tweaklets
This commit is contained in:
Luca Boccassi 2021-09-15 21:48:39 +01:00 committed by GitHub
commit a51f6dba60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,7 @@ static int update_timeout(void) {
flags = WDIOS_DISABLECARD; flags = WDIOS_DISABLECARD;
if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0)
return log_warning_errno(errno, "Failed to disable hardware watchdog: %m"); return log_warning_errno(errno, "Failed to disable hardware watchdog, ignoring: %m");
} else { } else {
int sec, flags; int sec, flags;
usec_t t; usec_t t;
@ -38,7 +38,7 @@ static int update_timeout(void) {
t = DIV_ROUND_UP(watchdog_timeout, USEC_PER_SEC); t = DIV_ROUND_UP(watchdog_timeout, USEC_PER_SEC);
sec = MIN(t, (usec_t) INT_MAX); /* Saturate */ sec = MIN(t, (usec_t) INT_MAX); /* Saturate */
if (ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec) < 0) if (ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec) < 0)
return log_warning_errno(errno, "Failed to set timeout to %is: %m", sec); return log_warning_errno(errno, "Failed to set timeout to %is, ignoring: %m", sec);
/* Just in case the driver is buggy */ /* Just in case the driver is buggy */
assert(sec > 0); assert(sec > 0);
@ -50,14 +50,14 @@ static int update_timeout(void) {
flags = WDIOS_ENABLECARD; flags = WDIOS_ENABLECARD;
if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) { if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) {
/* ENOTTY means the watchdog is always enabled so we're fine */ /* ENOTTY means the watchdog is always enabled so we're fine */
log_full(ERRNO_IS_NOT_SUPPORTED(errno) ? LOG_DEBUG : LOG_WARNING, log_full_errno(ERRNO_IS_NOT_SUPPORTED(errno) ? LOG_DEBUG : LOG_WARNING, errno,
"Failed to enable hardware watchdog: %m"); "Failed to enable hardware watchdog, ignoring: %m");
if (!ERRNO_IS_NOT_SUPPORTED(errno)) if (!ERRNO_IS_NOT_SUPPORTED(errno))
return -errno; return -errno;
} }
if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0) if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0)
return log_warning_errno(errno, "Failed to ping hardware watchdog: %m"); return log_warning_errno(errno, "Failed to ping hardware watchdog, ignoring: %m");
watchdog_last_ping = now(clock_boottime_or_monotonic()); watchdog_last_ping = now(clock_boottime_or_monotonic());
} }
@ -75,10 +75,10 @@ static int open_watchdog(void) {
fn = watchdog_device ?: "/dev/watchdog"; fn = watchdog_device ?: "/dev/watchdog";
watchdog_fd = open(fn, O_WRONLY|O_CLOEXEC); watchdog_fd = open(fn, O_WRONLY|O_CLOEXEC);
if (watchdog_fd < 0) if (watchdog_fd < 0)
return log_debug_errno(errno, "Failed to open watchdog device %s: %m", fn); return log_debug_errno(errno, "Failed to open watchdog device %s, ignoring: %m", fn);
if (ioctl(watchdog_fd, WDIOC_GETSUPPORT, &ident) < 0) if (ioctl(watchdog_fd, WDIOC_GETSUPPORT, &ident) < 0)
log_debug_errno(errno, "Hardware watchdog %s does not support WDIOC_GETSUPPORT ioctl: %m", fn); log_debug_errno(errno, "Hardware watchdog %s does not support WDIOC_GETSUPPORT ioctl, ignoring: %m", fn);
else else
log_info("Using hardware watchdog '%s', version %x, device %s", log_info("Using hardware watchdog '%s', version %x, device %s",
ident.identity, ident.identity,
@ -156,7 +156,7 @@ int watchdog_ping(void) {
} }
if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0) if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0)
return log_warning_errno(errno, "Failed to ping hardware watchdog: %m"); return log_warning_errno(errno, "Failed to ping hardware watchdog, ignoring: %m");
watchdog_last_ping = ntime; watchdog_last_ping = ntime;
return 0; return 0;
@ -172,7 +172,7 @@ void watchdog_close(bool disarm) {
/* Explicitly disarm it */ /* Explicitly disarm it */
flags = WDIOS_DISABLECARD; flags = WDIOS_DISABLECARD;
if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0)
log_warning_errno(errno, "Failed to disable hardware watchdog: %m"); log_warning_errno(errno, "Failed to disable hardware watchdog, ignoring: %m");
/* To be sure, use magic close logic, too */ /* To be sure, use magic close logic, too */
for (;;) { for (;;) {
@ -182,7 +182,7 @@ void watchdog_close(bool disarm) {
break; break;
if (errno != EINTR) { if (errno != EINTR) {
log_error_errno(errno, "Failed to disarm watchdog timer: %m"); log_warning_errno(errno, "Failed to disarm watchdog timer, ignoring: %m");
break; break;
} }
} }