1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 00:51:24 +03:00

watchdog: allow a device path to be specified

Currently systemd hardcodes the use of /dev/watchdog. This is a legacy
chardev that points to watchdog0 in the system.

Modify the watchdog API to allow a different device path to be passed
and stored. Opening the watchdog defaults to /dev/watchdog, maintaining
existing behavior.
This commit is contained in:
Edward A. James 2017-12-08 11:26:30 -06:00
parent 8208c8f25d
commit e4c98db335
2 changed files with 13 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}