/** Launches a thread that periodically checks if any of the connections has timed out @param arg Must contain a pointer to a string containing the IP adress of the client to check to check @todo Also pass MAC adress? @todo This thread loops infinitely, need a watchdog to verify that it is still running? */ void thread_client_timeout_check(const void *arg) { pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; struct timespec timeout; while (1) { /* Sleep for config.checkinterval seconds... */ timeout.tv_sec = time(NULL) + config_get_config()->checkinterval; timeout.tv_nsec = 0; /* Mutex must be locked for pthread_cond_timedwait... */ pthread_mutex_lock(&cond_mutex); /* Thread safe "sleep" */ pthread_cond_timedwait(&cond, &cond_mutex, &timeout); /* No longer needs to be locked */ pthread_mutex_unlock(&cond_mutex); debug(LOG_DEBUG, "Running fw_counter()"); fw_sync_with_authserver(); } }
/** Launches a thread that periodically checks if any of the connections has timed out @param arg Must contain a pointer to a string containing the IP adress of the client to check to check @todo Also pass MAC adress? @todo This thread loops infinitely, need a watchdog to verify that it is still running? */ void thread_client_timeout_check(const void *arg) { pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; struct timespec timeout; /*open named pipes to/from mysql server*/ FILE * mysql_request = fopen("/tmp/wifidog_mysql_request_fifo","w"); FILE * mysql_response = fopen("/tmp/wifidog_mysql_response_fifo","r"); // char mysql_buf[256]; /* // set response fifo nonblocking,.. int fd=fileno(mysql_response); int flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK); //!!?? write ahelper function for this, as we might have to change this quite often,.. debug(LOG_DEBUG,"mysql filedescriptors request: %d response: %d", fileno(mysql_request),fd); // empty the response fifo while (NULL != fgets(mysql_buf, sizeof(mysql_buf), mysql_response) ) { debug(LOG_DEBUG,"unexpected mysql response: %s", mysql_buf); } // test mysql with a simple query fputs("SELECT 1;\n", mysql_request); fflush(mysql_request); sleep(1); //!!?? write a helper functions that waits up to timeout for an response, or use a timeout instead of nonblocking?, or use blocking(together with column header it would be ok) if ( NULL == fgets(mysql_buf, sizeof(mysql_buf), mysql_response) ){ fputs("\nexit\n", mysql_request); fflush(mysql_request); debug(LOG_ERR,"mysql does not work: reverting to http-reauthentication"); mysql_request = NULL; mysql_response = NULL; } else debug(LOG_DEBUG,"mysql response was: %s",mysql_buf); */ while (1) { /* Sleep for config.checkinterval seconds... */ timeout.tv_sec = time(NULL) + config_get_config()->checkinterval; timeout.tv_nsec = 0; /* Mutex must be locked for pthread_cond_timedwait... */ pthread_mutex_lock(&cond_mutex); /* Thread safe "sleep" */ pthread_cond_timedwait(&cond, &cond_mutex, &timeout); /* No longer needs to be locked */ pthread_mutex_unlock(&cond_mutex); debug(LOG_DEBUG, "Running fw_counter()"); fw_sync_with_authserver(mysql_request, mysql_response); } }