diff options
Diffstat (limited to 'src/shared/watchdog.c')
-rw-r--r-- | src/shared/watchdog.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index 690493a698..8c8f1893f7 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -314,7 +314,7 @@ static int update_timeout(void) { static int open_watchdog(void) { struct watchdog_info ident; - const char *fn; + char **try_order; int r; if (watchdog_fd >= 0) @@ -324,16 +324,25 @@ static int open_watchdog(void) { * has the benefit that we can easily find the matching directory in sysfs from it, as the relevant * sysfs attributes can only be found via /sys/dev/char/<major>:<minor> if the new-style device * major/minor is used, not the old-style. */ - fn = !watchdog_device || path_equal(watchdog_device, "/dev/watchdog") ? - "/dev/watchdog0" : watchdog_device; + try_order = !watchdog_device || PATH_IN_SET(watchdog_device, "/dev/watchdog", "/dev/watchdog0") ? + STRV_MAKE("/dev/watchdog0", "/dev/watchdog") : STRV_MAKE(watchdog_device); - r = free_and_strdup(&watchdog_device, fn); - if (r < 0) - return log_oom_debug(); + STRV_FOREACH(wd, try_order) { + watchdog_fd = open(*wd, O_WRONLY|O_CLOEXEC); + if (watchdog_fd >= 0) { + r = free_and_strdup(&watchdog_device, *wd); + if (r < 0) + return log_oom_debug(); + + break; + } + + if (errno != ENOENT) + return log_debug_errno(errno, "Failed to open watchdog device %s: %m", *wd); + } - watchdog_fd = open(watchdog_device, O_WRONLY|O_CLOEXEC); if (watchdog_fd < 0) - return log_debug_errno(errno, "Failed to open watchdog device %s, ignoring: %m", watchdog_device); + return log_debug_errno(SYNTHETIC_ERRNO(ENOENT), "Failed to open watchdog device %s: %m", watchdog_device ?: "auto"); if (ioctl(watchdog_fd, WDIOC_GETSUPPORT, &ident) < 0) log_debug_errno(errno, "Hardware watchdog %s does not support WDIOC_GETSUPPORT ioctl, ignoring: %m", watchdog_device); |