AHA!在挖掘内核的linux / watchdog.h和drivers / watchdog / softdog.c之后,我能够确定软件ioctl()接口的功能.看看它在struct watchdog_info中宣布的功能:
static struct watchdog_info ident = {
.options = WDIOF_SETTIMEOUT |
WDIOF_KEEPALIVEPING |
WDIOF_MAGICCLOSE,
.firmware_version = 0,
.identity = "Software Watchdog",
};
它支持一个魔术关闭(似乎)覆盖CONFIG_WATCHDOG_NOWAYOUT.所以,当正常终止时,我必须将一个char’V’写入/ dev / watchdog,然后关闭它,并且定时器将停止计数.
对/ dev / watchdog的文件描述符的简单ioctl(),询问WDIOC_GETSUPPORT允许用户确定是否设置了该标志.伪码:
int fd;
struct watchdog_info info;
fd = open("/dev/watchdog", O_WRONLY);
if (fd == -1) {
perror("open");
// abort, timer did not start - no additional concerns
}
if (ioctl(fd, WDIOC_GETSUPPORT, &info)) {
perror("ioctl");
// abort, but you probably started the timer! See below.
}
if (WDIOF_MAGICCLOSE & info.options) {
printf("Watchdog supports magic close char\n");
// You have started the timer here! Handle that appropriately.
}
当使用硬件看门狗时,您可能需要使用O_NONBLOCK打开,以便ioctl()不会打开()块(从而检测到忙卡).
如果不支持WDIOF_MAGICCLOSE,则应该假设软看门狗配置为NOWAYOUT.记住,只要打开设备就能成功启动倒计时.如果你所做的一切正在探索是否支持魔法关闭,那么魔法就会关闭它.否则,一定要处理你现在有一个运行看门狗的事实.
不幸的是,没有真正的方法可以肯定地知道,没有真正的开始,至少不是我能找到.