
RSB-4210 User Manual 86
3.11.8 WatchDog
Usually an userspace daemon will notify the kernel watchdog driver via the/dev/
watchdog special device file that userspace is still alive, at regular intervals. When
such a notification occurs, the driver will usually tell the hardware watchdog that
everything is in order, and that the watchdog should wait for yet another little while to
reset the system. If userspace fails (RAM error, kernel bug, whatever), the notifica-
tions cease to occur, and the hardware watchdog will reset the system (causing a
reboot) after the timeout occurs.
3.11.8.1 The Simplest API
All drivers support the basic mode of operation, where the watchdog activates as
soon as /dev/watchdog is opened and will reboot unless the watchdog is pinged
within a certain time, this time is called the timeout or margin. The simplest way to
ping the watchdog is to write some data to the device. So a very simple watchdog
daemon would look like this source file as below:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(void)
{
int fd = open("/dev/watchdog", O_WRONLY);
int ret = 0;
if (fd == -1) {
perror("watchdog");
exit(EXIT_FAILURE);
}
while (1) {
ret = write(fd, "\0", 1);
if (ret != 1) {
ret = -1;
break;
}
sleep(10);
}
close(fd);
return ret;
}
3.11.8.2 Magic Close feature
If a driver supports "Magic Close", the driver will not disable the watchdog unless a
specific magic character 'V' has been sent to /dev/watchdog just before closing the
file. If the userspace daemon closes the file without sending this special character,
the driver will assume that the daemon (and userspace in general) died, and will stop
pinging the watchdog without disabling it first. This will then cause a reboot if the
watchdog is not re-opened in sufficient time.
Comentarios a estos manuales