contrib/package/freifunk-watchdog: better handle checking for uci updates
[project/luci.git] / contrib / package / freifunk-watchdog / src / watchdog.c
index 12d4bad..c269f22 100644 (file)
@@ -69,7 +69,7 @@ static int iw_get_channel(int iwfd, const char *ifname, int *channel)
                }
 
                for(i = 0; i < range->num_frequency; i++)
-           {
+               {
                        cmp_freq = ((double)range->freq[i].m) * pow(10, range->freq[i].e);
                        if( cmp_freq == cur_freq )
                        {
@@ -137,7 +137,7 @@ static int check_uci_update(const char *config, time_t *mtime)
        struct stat s;
        char path[128];
 
-       snprintf(path, sizeof(path), "/etc/config/%s", config);
+       snprintf(path, sizeof(path), "/var/state/%s", config);
        if( stat(path, &s) > -1 )
        {
                if( (*mtime == 0) || (s.st_mtime > *mtime) )
@@ -145,20 +145,8 @@ static int check_uci_update(const char *config, time_t *mtime)
                        *mtime = s.st_mtime;
                        return 1;
                }
-               else
-               {
-                       snprintf(path, sizeof(path), "/var/state/%s", config);
-                       if( stat(path, &s) > -1 )
-                       {
-                               if( (*mtime == 0) || (s.st_mtime > *mtime) )
-                               {
-                                       *mtime = s.st_mtime;
-                                       return 1;
-                               }
-                       }
 
-                       return 0;
-               }
+               return 0;
        }
 
        return -1;
@@ -302,7 +290,7 @@ static int do_daemon(void)
                                }
 
                                /* Check channel */
-                               if( channel != curif->channel )
+                               else if( channel != curif->channel )
                                {
                                        syslog(LOG_WARNING, "Channel mismatch on %s: current=%d wanted=%d",
                                                curif->ifname, channel, curif->channel);
@@ -318,16 +306,18 @@ static int do_daemon(void)
 
 
                /* Wifi restart required? */
-               if( restart_wifi > 0 )
+               if( restart_wifi >= HYSTERESIS )
                {
                        restart_wifi = 0;
+                       syslog(LOG_WARNING, "Restarting wireless");
                        EXEC(WIFI_ACTION);
                }
 
                /* Cron restart required? */
-               if( restart_cron > 0 )
+               if( restart_cron >= HYSTERESIS )
                {
                        restart_cron = 0;
+                       syslog(LOG_WARNING, "Restarting crond process");
                        EXEC(CRON_ACTION);      
                }