aboutsummaryrefslogtreecommitdiff
path: root/wd/wdd.c
diff options
context:
space:
mode:
Diffstat (limited to 'wd/wdd.c')
-rw-r--r--wd/wdd.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/wd/wdd.c b/wd/wdd.c
new file mode 100644
index 0000000..3ee0af8
--- /dev/null
+++ b/wd/wdd.c
@@ -0,0 +1,38 @@
+/*
+ * wdd - simple watchdog daemon - 2003 - willy tarreau
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+const char dev_wd_str[] = "/dev/watchdog";
+const char root_str[] = "/";
+
+int main (void) {
+ int dev;
+
+ if (fork() > 0)
+ return 0;
+ for (dev = 2; dev >= 0; dev--)
+ close(dev);
+ chdir(root_str);
+ setsid();
+ /* let's try indefinitely to open the watchdog device */
+ /* note that dev is -1 now ;-) */
+ while (1) {
+ if (dev == -1)
+ dev = open(dev_wd_str, O_RDWR);
+ if ((dev != -1) && (write(dev, dev_wd_str, 1) != 1)) {
+ /* write error, we'll restart */
+ close(dev);
+ dev = -1;
+ }
+ /* avoid a fast loop */
+ sleep(1);
+ }
+ /* we never get there theorically... */
+ return 0;
+}
+