blob: 7dddd6172cddc1a82549b6b407aa8207499044fb [file] [log] [blame]
From 9d1f2858cd2ba49066ca319164b4e3e2769fc0fb Mon Sep 17 00:00:00 2001
From: "Edward A. James" <eajames@us.ibm.com>
Date: Fri, 8 Dec 2017 11:26:30 -0600
Subject: [PATCH 1/3] 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.
---
src/shared/watchdog.c | 9 ++++++++-
src/shared/watchdog.h | 5 +++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c
index 4f3e012..8068e95 100644
--- a/src/shared/watchdog.c
+++ b/src/shared/watchdog.c
@@ -26,10 +26,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) {
@@ -83,7 +85,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;
@@ -95,6 +98,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 f6ec178..90a075a 100644
--- a/src/shared/watchdog.h
+++ b/src/shared/watchdog.h
@@ -24,6 +24,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);
+}
--
1.8.3.1