/* wathchdog is runned in NORMAL_PERIOD, 1 seconds * check in each NORMAL_PERIOD * 1. button * * check in each NORAML_PERIOD*10 * * 1. ntptime * 2. time-dependent service * 3. http-process */ static void watchdog(int sig) { /* handle button */ btn_check_reset(); btn_check_ez(); /* if timer is set to less than 1 sec, then bypass the following */ if (itv.it_value.tv_sec == 0) return; if (nvram_match("reboot", "1")) return; // watchdog interval = 10s watchdog_period = (watchdog_period + 1) % 10; if (watchdog_period) return; /* check for time-dependent services */ svc_timecheck(); /* http server check */ httpd_processcheck(); nmap_handler(); inet_handler(); }
/* wathchdog is runned in NORMAL_PERIOD, 1 seconds * check in each NORMAL_PERIOD * 1. button * * check in each NORAML_PERIOD*10 * * 1. ntptime * 2. time-dependent service * 3. http-process * 4. usb hotplug status */ void watchdog(void) { /* handle button */ btn_check(); /* if timer is set to less than 1 sec, then bypass the following */ if (itv.it_value.tv_sec == 0) return; if (nvram_match("asus_mfg", "1")) { system("rmmod hw_nat"); if (pids("ntp")) system("killall -SIGTERM ntp"); if (pids("ntpclient")) system("killall ntpclient"); if (pids("udhcpc")) system("killall -SIGTERM udhcpc"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) if (pids("ots")) system("killall ots"); #endif stop_wanduck(); stop_logger(); stop_upnp(); // it may cause upnp cannot run stop_dhcpd(); stop_dns(); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) stop_pspfix(); #endif stop_wsc(); stop_wsc_2g(); stop_lltd(); stop_networkmap(); stop_httpd(); stop_lpd(); stop_u2ec(); kill_pidfile_s("/var/run/linkstatus_monitor.pid", SIGTERM); if (pids("detectWan")) system("killall detectWan"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) stop_rstats(); kill_pidfile_s("/var/run/detect_internet.pid", SIGTERM); #endif if (pids("tcpcheck")) system("killall -SIGTERM tcpcheck"); #ifdef HTTPD_CHECK if (pids("httpdcheck")) system("killall -SIGTERM httpdcheck"); #endif if (pids("traceroute")) system("killall traceroute"); if (pids("usbled")) system("killall -SIGTERM usbled"); nvram_set("asus_mfg", "2"); } #if 0 // reboot signal checking if (nvram_match("reboot", "1")) { printf("[watchdog] nvram match reboot\n"); reboot_count++; if (reboot_count >= 2) { // kill(1, SIGTERM); sys_exit(); } return; } #else if (nvram_match("reboot", "1")) return; #endif if (stop_service_type_99) return; if (!nvram_match("asus_mfg", "0")) return; watchdog_period = (watchdog_period + 1) % 10; if (watchdog_period) return; #ifdef BTN_SETUP if (btn_pressed_setup >= BTNSETUP_START) return; #endif #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) if (count_to_stop_wps > 0) { count_to_stop_wps--; if (!count_to_stop_wps) { // if (nvram_match("wl_radio_x", "1")) stop_wsc(); // psp fix // if (nvram_match("rt_radio_x", "1")) stop_wsc_2g(); // psp fix nvram_set("wps_enable", "0"); // psp fix } } #endif ddns_timer = (ddns_timer + 1) % 4320; if (nvram_match("asus_debug", "1")) mem_timer = (mem_timer + 1) % 60; if (!watchdog_count) watchdog_count++; else if (watchdog_count++ == 1) { #if 0 if (!strcmp(nvram_safe_get("rc_service"), "restart_upnp")) service_handle(); else #endif if ( nvram_match("router_disable", "0") && nvram_match("upnp_enable", "1") && nvram_match("upnp_started", "0") ) { // if (has_wan_ip()) { dbg("[watchdog] starting upnp...\n"); stop_upnp(); start_upnp(); } } } /* check for time-dependent services */ svc_timecheck(); /* http server check */ httpd_processcheck(); u2ec_processcheck(); media_processcheck(); #if 0 samba_processcheck(); #endif pppd_processcheck(); if (nvram_match("wan_route_x", "IP_Routed")) nm_processcheck(); cpu_usage_minotor(); dm_block_chk(); if (nvram_match("asus_debug", "1") && !mem_timer) { print_num_of_connections(); dbg("Hardware NAT: %s\n", is_hwnat_loaded() ? "Enabled": "Disabled"); dbg("Software QoS: %s\n", nvram_match("qos_enable", "1") ? "Enabled": "Disabled"); dbg("pppd running: %s\n", pids("pppd") ? "Yes": "No"); #if 0 dbg("CPU usage: %d%%\n", get_cpu_usage()); #else dbg("CPU usage: %d%%\n", cpu_main(0, NULL, 0)); #endif system("free"); system("date"); print_uptime(); } #ifdef CDMA /* CDMA_DOWN = 99, none * CDMA_DOWN = 1, currently down * CDMA_DOWN = 2, currently up * CDMA_DOWN = 0, currently trying to connect */ if (nvram_match("cdma_down", "1")) { logmessage("CDMA client", "cdma is down(%d)!", cdma_down); cdma_down++; cdma_connec t = 0; if (cdma_down == 2) { printf("[watchdog] stop wan\n"); stop_wan(); start_wan(); } else if (cdma_down >= 12) /* 2 minutes timeout for retry */ { cdma_down = 0; } } else if (nvram_match("cdma_down", "0")) { logmessage("CDMA client", "cdma try connect(%d)!", cdma_connect); cdma_down = 0; cdma_connect++; if (cdma_connect > 12) /* 2 minitues timeout for connecting */ { nvram_set("cdma_down", "1"); } } else { cdma_down = 0; cdma_connect = 0; } #endif if (nvram_match("wan_route_x", "IP_Routed")) { if (!is_phyconnected() || !has_wan_ip()) return; /* sync time to ntp server if necessary */ if (!nvram_match("wan_dns_t", "") && !nvram_match("wan_gateway_t", "")) { ntp_timesync(); } if ( nvram_match("ddns_enable_x", "1") && (!nvram_match("ddns_updated", "1") || !ddns_timer) ) { logmessage("RT-N56U", "[start ddns] watchdog"); start_ddns(); } if (!ddns_timer) { stop_networkmap(); start_networkmap(); } } else { if (/*!nvram_match("lan_dns_t", "") && */!nvram_match("lan_gateway_t", "")) ntp_timesync(); } }