summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-13 21:55:35 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-16 15:34:37 +0200
commita6b7ebaafa73205f4fc80dd307013fb714ebbd76 (patch)
tree5e0fc1a2878e1beb05776dc881ecd97dacb04605
parentsd-device-monitor: do not trigger assertion when uid_map is not empty (diff)
downloadsystemd-a6b7ebaafa73205f4fc80dd307013fb714ebbd76.tar.xz
systemd-a6b7ebaafa73205f4fc80dd307013fb714ebbd76.zip
watchdog: use /dev/watchdog0 only if it exists
Fixes #24661.
-rw-r--r--src/shared/watchdog.c25
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);