看门狗定时器

在procd中看到的看门狗。(不过从日志上看其实看门狗是没有生效的,从openwrt的配置文件上看看门狗是需要配置的)

参考资料:https://blog.csdn.net/xiaopohaibebo/article/details/8090916

procd中相关函数:

 1 void watchdog_init(int preinit)
 2 {
 3     char *env = getenv("WDTFD");
 4 
 5     if (wdt_fd >= 0)
 6         return;
 7 
 8     wdt_timeout.cb = watchdog_timeout_cb;
 9     if (env) {
10         DEBUG(2, "Watchdog handover: fd=%s
", env);
11         wdt_fd = atoi(env);
12         unsetenv("WDTFD");
13     } else {
14          wdt_fd = open("/dev/watchdog", O_WRONLY);
15     }
16 
17     if (wdt_fd < 0)
18         return;
19 
20     if (!preinit)
21         fcntl(wdt_fd, F_SETFD, fcntl(wdt_fd, F_GETFD) | FD_CLOEXEC);
22 
23     LOG("- watchdog -
");
24     watchdog_timeout(30);/*设置超时时间*/
25     watchdog_timeout_cb(&wdt_timeout);/*定时喂狗*/
26 
27     DEBUG(4, "Opened watchdog with timeout %ds
", watchdog_timeout(0));
28 }
29 
30 static void watchdog_timeout_cb(struct uloop_timeout *t)
31 {
32     watchdog_ping();/*喂狗*/
33     uloop_timeout_set(t, wdt_frequency * 1000 );/*重新定时*/
34 }
35 
36 void watchdog_ping(void)
37 {
38     DEBUG(4, "Ping
");
39     if (wdt_fd >=0 && write(wdt_fd, "X", 1) < 0)
40         ERROR("WDT failed to write: %s
", strerror(errno));
41 }
原文地址:https://www.cnblogs.com/laymond/p/10042732.html