diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index a6a356dbd07..b0a422da849 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -27,10 +27,12 @@ #include "fd-util.h" #include "log.h" +#include "string-util.h" #include "time-util.h" #include "watchdog.h" static int watchdog_fd = -1; +static char *watchdog_device = NULL; static usec_t watchdog_timeout = USEC_INFINITY; static int update_timeout(void) { @@ -84,7 +86,8 @@ static int open_watchdog(void) { if (watchdog_fd >= 0) return 0; - watchdog_fd = open("/dev/watchdog", O_WRONLY|O_CLOEXEC); + watchdog_fd = open(watchdog_device ?: "/dev/watchdog", + O_WRONLY|O_CLOEXEC); if (watchdog_fd < 0) return -errno; @@ -96,6 +99,10 @@ static int open_watchdog(void) { return update_timeout(); } +int watchdog_set_device(char *path) { + return free_and_strdup(&watchdog_device, path); +} + int watchdog_set_timeout(usec_t *usec) { int r; diff --git a/src/shared/watchdog.h b/src/shared/watchdog.h index 8c17e7e1dc2..5694338db3a 100644 --- a/src/shared/watchdog.h +++ b/src/shared/watchdog.h @@ -25,6 +25,11 @@ #include "time-util.h" #include "util.h" +int watchdog_set_device(char *path); int watchdog_set_timeout(usec_t *usec); int watchdog_ping(void); void watchdog_close(bool disarm); + +static inline void watchdog_free_device(void) { + (void) watchdog_set_device(NULL); +}