啊哈!深入挖掘内核之后linux/watchdog.h
and 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",
};
It does支持(似乎)覆盖的魔法关闭CONFIG_WATCHDOG_NOWAYOUT
。因此,当正常终止时,我必须写入一个字符“V”/dev/watchdog
then关闭它,计时器将停止计时。
一个简单的ioctl()
在文件描述符上/dev/watchdog
asking 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
so ioctl()
not open()
块(因此检测到繁忙的卡)。
If WDIOF_MAGICCLOSE
不支持,我们应该假设软看门狗配置为NOWAYOUT。记住,只要opening设备成功开始倒计时。如果您所做的只是探测它是否支持 magic close 并且确实支持,那么魔法关闭它。否则,请务必处理您现在有一个正在运行的看门狗的事实。
不幸的是,如果不实际启动,就没有真正的方法可以确定,至少我找不到。