zoukankan      html  css  js  c++  java
  • 看门狗定时器

    在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 }
  • 相关阅读:
    Git+GitHub+SaltStack
    系统运维
    Linux之Ubuntu
    TCP/IP 必知必会的十个问题
    Github常见操作和常见错误!
    Git钩子:自定义你的工作流
    Spring 梳理
    Spring 梳理
    Spring 梳理
    Spring boot 官网学习笔记
  • 原文地址:https://www.cnblogs.com/laymond/p/10042732.html
Copyright © 2011-2022 走看看