Edward A. James | aa111ab | 2017-11-29 15:47:23 -0600 | [diff] [blame] | 1 | From 9d1f2858cd2ba49066ca319164b4e3e2769fc0fb Mon Sep 17 00:00:00 2001 |
| 2 | From: "Edward A. James" <eajames@us.ibm.com> |
| 3 | Date: Fri, 8 Dec 2017 11:26:30 -0600 |
| 4 | Subject: [PATCH 1/3] watchdog: allow a device path to be specified |
| 5 | |
| 6 | Currently systemd hardcodes the use of /dev/watchdog. This is a legacy |
| 7 | chardev that points to watchdog0 in the system. |
| 8 | |
| 9 | Modify the watchdog API to allow a different device path to be passed |
| 10 | and stored. Opening the watchdog defaults to /dev/watchdog, maintaining |
| 11 | existing behavior. |
| 12 | --- |
| 13 | src/shared/watchdog.c | 9 ++++++++- |
| 14 | src/shared/watchdog.h | 5 +++++ |
| 15 | 2 files changed, 13 insertions(+), 1 deletion(-) |
| 16 | |
| 17 | diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c |
| 18 | index 4f3e012..8068e95 100644 |
| 19 | --- a/src/shared/watchdog.c |
| 20 | +++ b/src/shared/watchdog.c |
| 21 | @@ -26,10 +26,12 @@ |
| 22 | |
| 23 | #include "fd-util.h" |
| 24 | #include "log.h" |
| 25 | +#include "string-util.h" |
| 26 | #include "time-util.h" |
| 27 | #include "watchdog.h" |
| 28 | |
| 29 | static int watchdog_fd = -1; |
| 30 | +static char *watchdog_device = NULL; |
| 31 | static usec_t watchdog_timeout = USEC_INFINITY; |
| 32 | |
| 33 | static int update_timeout(void) { |
| 34 | @@ -83,7 +85,8 @@ static int open_watchdog(void) { |
| 35 | if (watchdog_fd >= 0) |
| 36 | return 0; |
| 37 | |
| 38 | - watchdog_fd = open("/dev/watchdog", O_WRONLY|O_CLOEXEC); |
| 39 | + watchdog_fd = open(watchdog_device ?: "/dev/watchdog", |
| 40 | + O_WRONLY|O_CLOEXEC); |
| 41 | if (watchdog_fd < 0) |
| 42 | return -errno; |
| 43 | |
| 44 | @@ -95,6 +98,10 @@ static int open_watchdog(void) { |
| 45 | return update_timeout(); |
| 46 | } |
| 47 | |
| 48 | +int watchdog_set_device(char *path) { |
| 49 | + return free_and_strdup(&watchdog_device, path); |
| 50 | +} |
| 51 | + |
| 52 | int watchdog_set_timeout(usec_t *usec) { |
| 53 | int r; |
| 54 | |
| 55 | diff --git a/src/shared/watchdog.h b/src/shared/watchdog.h |
| 56 | index f6ec178..90a075a 100644 |
| 57 | --- a/src/shared/watchdog.h |
| 58 | +++ b/src/shared/watchdog.h |
| 59 | @@ -24,6 +24,11 @@ |
| 60 | #include "time-util.h" |
| 61 | #include "util.h" |
| 62 | |
| 63 | +int watchdog_set_device(char *path); |
| 64 | int watchdog_set_timeout(usec_t *usec); |
| 65 | int watchdog_ping(void); |
| 66 | void watchdog_close(bool disarm); |
| 67 | + |
| 68 | +static inline void watchdog_free_device(void) { |
| 69 | + (void) watchdog_set_device(NULL); |
| 70 | +} |
| 71 | -- |
| 72 | 1.8.3.1 |
| 73 | |