[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Embedded-pv-devel] [PATCH RFC 07/18] tools/misc: Modify Xen watchdog daemon



From: Viktor Kleinik <viktor.kleinik@xxxxxxxxxxxxxxx>

This change allows watchdog daemon to work thru watchdog device
on the file system.

Signed-off-by: Viktor Kleinik <viktor.kleinik@xxxxxxxxxxxxxxx>
---
 tools/misc/xenwatchdogd.c | 52 +++++++++++------------------------------------
 1 file changed, 12 insertions(+), 40 deletions(-)

diff --git a/tools/misc/xenwatchdogd.c b/tools/misc/xenwatchdogd.c
index 254117b..4b27628 100644
--- a/tools/misc/xenwatchdogd.c
+++ b/tools/misc/xenwatchdogd.c
@@ -1,17 +1,17 @@
-
 #include <err.h>
 #include <limits.h>
-#include "xenctrl.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <signal.h>
 #include <stdio.h>
+#include <sys/ioctl.h>
+#include <linux/watchdog.h>
+
+#define DEV_NAME "/dev/watchdog"
 
-xc_interface *h;
-int id = 0;
+int fd = -1;
 
 void daemonize(void)
 {
@@ -36,20 +36,6 @@ void daemonize(void)
         err(1, "reopen stderr");
 }
 
-void catch_exit(int sig)
-{
-    if (id)
-        xc_watchdog(h, id, 300);
-    exit(0);
-}
-
-void catch_usr1(int sig)
-{
-    if (id)
-        xc_watchdog(h, id, 0);
-    exit(0);
-}
-
 int main(int argc, char **argv)
 {
     int t, s;
@@ -60,9 +46,9 @@ int main(int argc, char **argv)
 
     daemonize();
 
-    h = xc_interface_open(NULL, NULL, 0);
-    if (h == NULL)
-       err(1, "xc_interface_open");
+    fd = open(DEV_NAME, O_RDWR);
+    if (fd < 0)
+        err(1, "xenwatchdogd: Failed to open %s\n", DEV_NAME);
 
     t = strtoul(argv[1], NULL, 0);
     if (t == ULONG_MAX)
@@ -75,25 +61,11 @@ int main(int argc, char **argv)
            err(1, "strtoul");
     }
 
-    if (signal(SIGHUP, &catch_exit) == SIG_ERR)
-       err(1, "signal");
-    if (signal(SIGINT, &catch_exit) == SIG_ERR)
-       err(1, "signal");
-    if (signal(SIGQUIT, &catch_exit) == SIG_ERR)
-       err(1, "signal");
-    if (signal(SIGTERM, &catch_exit) == SIG_ERR)
-       err(1, "signal");
-    if (signal(SIGUSR1, &catch_usr1) == SIG_ERR)
-       err(1, "signal");
-
-    id = xc_watchdog(h, 0, t);
-    if (id <= 0)
-        err(1, "xc_watchdog setup");
-
     for (;;) {
+       ret = ioctl(fd, WDIOC_KEEPALIVE);
+       if (ret)
+           err(1, "xenwatchdogd: Failed to kick watchdog\n");
+
         sleep(s);
-        ret = xc_watchdog(h, id, t);
-        if (ret != 0)
-            err(1, "xc_watchdog");
     }
 }
-- 
2.8.2


_______________________________________________
Embedded-pv-devel mailing list
Embedded-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/embedded-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.