From 265cc664ff5ffd08dd3ce30396e8573b7baf1488 Mon Sep 17 00:00:00 2001 From: Federico Simoncelli Date: Tue, 20 Nov 2012 11:52:22 -0500 Subject: [PATCH] wdmd: make the watchdog device configurable Signed-off-by: Federico Simoncelli --- src/sysconfig.sanlock => init.d/sanlock.sysconfig | 0 wdmd/sysconfig.wdmd => init.d/wdmd.sysconfig | 3 +++ wdmd/main.c | 29 +++++++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) rename src/sysconfig.sanlock => init.d/sanlock.sysconfig (100%) rename wdmd/sysconfig.wdmd => init.d/wdmd.sysconfig (73%) diff --git a/src/sysconfig.sanlock b/init.d/sanlock.sysconfig similarity index 100% rename from src/sysconfig.sanlock rename to init.d/sanlock.sysconfig diff --git a/wdmd/sysconfig.wdmd b/init.d/wdmd.sysconfig similarity index 73% rename from wdmd/sysconfig.wdmd rename to init.d/wdmd.sysconfig index 06a13db..1ef8564 100644 --- a/wdmd/sysconfig.wdmd +++ b/init.d/wdmd.sysconfig @@ -5,4 +5,7 @@ # # To enable use of test scripts #WDMDOPTS="-G sanlock -S 1" +# +# To select a specific watchdog device +#WDMDOPTS="-G sanlock -w /dev/watchdog1" diff --git a/wdmd/main.c b/wdmd/main.c index 482ab29..ff2d57c 100644 --- a/wdmd/main.c +++ b/wdmd/main.c @@ -64,6 +64,7 @@ static int shm_fd; static int allow_scripts; static int kill_script_sec; static char *scripts_dir = (char *)"/etc/wdmd.d"; +static char *watchdog_path = "/dev/watchdog"; struct script_status { uint64_t start; @@ -921,13 +922,13 @@ static int open_dev(void) int fd; if (dev_fd != -1) { - log_error("/dev/watchdog already open fd %d", dev_fd); + log_error("watchdog already open fd %d", dev_fd); return -1; } - fd = open("/dev/watchdog", O_WRONLY | O_CLOEXEC); + fd = open(watchdog_path, O_WRONLY | O_CLOEXEC); if (fd < 0) { - log_error("no /dev/watchdog, load a watchdog driver"); + log_error("no %s, load a watchdog driver", watchdog_path); return fd; } @@ -942,7 +943,7 @@ static void close_watchdog_unclean(void) return; } - log_error("/dev/watchdog closed unclean"); + log_error("%s closed unclean", watchdog_path); close(dev_fd); dev_fd = -1; @@ -960,9 +961,9 @@ static void close_watchdog(void) rv = write(dev_fd, "V", 1); if (rv < 0) - log_error("/dev/watchdog disarm write error %d", errno); + log_error("%s disarm write error %d", watchdog_path, errno); else - log_error("/dev/watchdog disarmed"); + log_error("%s disarmed", watchdog_path); close(dev_fd); dev_fd = -1; @@ -980,7 +981,7 @@ static int setup_watchdog(void) rv = ioctl(dev_fd, WDIOC_GETTIMEOUT, &timeout); if (rv < 0) { - log_error("/dev/watchdog failed to report timeout"); + log_error("%s failed to report timeout", watchdog_path); close_watchdog(); return -1; } @@ -992,18 +993,18 @@ static int setup_watchdog(void) rv = ioctl(dev_fd, WDIOC_SETTIMEOUT, &timeout); if (rv < 0) { - log_error("/dev/watchdog failed to set timeout"); + log_error("%s failed to set timeout", watchdog_path); close_watchdog(); return -1; } if (timeout != fire_timeout) { - log_error("/dev/watchdog failed to set new timeout"); + log_error("%s failed to set new timeout", watchdog_path); close_watchdog(); return -1; } out: - log_error("/dev/watchdog armed with fire_timeout %d", fire_timeout); + log_error("%s armed with fire_timeout %d", watchdog_path, fire_timeout); return 0; } @@ -1150,7 +1151,7 @@ static int test_loop(void) if (dev_fd == -1) { open_dev(); pet_watchdog(); - log_error("/dev/watchdog reopen"); + log_error("%s reopen", watchdog_path); } else { pet_watchdog(); } @@ -1326,6 +1327,7 @@ static void print_usage_and_exit(int status) printf("-s path to scripts dir (default %s)\n", scripts_dir); printf("-k kill unfinished scripts after num seconds (default %d)\n", kill_script_sec); + printf("-w /dev/watchdog path to the watchdog device (default %s)\n", watchdog_path); exit(status); } @@ -1358,7 +1360,7 @@ int main(int argc, char *argv[]) {0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hdVDH:G:S:s:k:", + c = getopt_long(argc, argv, "hdVDH:G:S:s:k:w:", long_options, &option_index); if (c == -1) break; @@ -1391,6 +1393,9 @@ int main(int argc, char *argv[]) case 'k': kill_script_sec = atoi(optarg); break; + case 'w': + watchdog_path = strdup(optarg); + break; } } -- 1.7.11.7