blob: 3ee0af8bd26af523c7c3e5365e0073aba984a4f0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}
|