Show
Ignore:
Timestamp:
02/03/05 23:05:28 (8 years ago)
Author:
minaguib
Message:

Keep track of whether we're online or not, show user apology if we're not
Fix building ipkg's - didn't work on my openwrt build
Fix memory leak
Misc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/src/util.c

    r422 r424  
    5151 
    5252static pthread_mutex_t ghbn_mutex = PTHREAD_MUTEX_INITIALIZER; 
     53 
     54/* XXX Do these need to be locked ? */ 
     55static time_t last_online_time = 0; 
     56static time_t last_offline_time = 0; 
    5357 
    5458/** Fork a child and execute a shell command, the parent 
     
    108112        if (he == NULL) { 
    109113                free(h_addr); 
     114                mark_offline(); 
    110115                UNLOCK_GHBN(); 
    111116                return NULL; 
    112117        } 
     118 
     119        mark_online(); 
    113120 
    114121        in_addr_temp = (struct in_addr *)he->h_addr_list[0]; 
     
    145152    return (char *)inet_ntoa(in); 
    146153} 
     154 
     155void mark_online() { 
     156        time(&last_online_time); 
     157} 
     158 
     159void mark_offline() { 
     160        time(&last_offline_time); 
     161} 
     162 
     163int is_online() { 
     164        if (last_online_time == 0 || (last_offline_time - last_online_time) >= (config_get_config()->checkinterval * 2) ) { 
     165                /* We're probably offline */ 
     166                return (0); 
     167        } 
     168        else { 
     169                /* We're probably online */ 
     170                return (1); 
     171        } 
     172} 
     173