Merge branch 'feature/switch_to_uloop'

This commit is contained in:
PolynomialDivision 2017-11-20 19:39:18 +01:00
commit d33a746e83
4 changed files with 2 additions and 89 deletions

View file

@ -8,7 +8,6 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <libubox/uloop.h>
#ifndef ETH_ALEN #ifndef ETH_ALEN
#define ETH_ALEN 6 #define ETH_ALEN 6
@ -92,8 +91,6 @@ void print_probe_entry(probe_entry entry);
void print_auth_entry(auth_entry entry); void print_auth_entry(auth_entry entry);
void *remove_probe_array_thread(void *arg);
void uloop_add_data_cbs(); void uloop_add_data_cbs();
/* AP, Client */ /* AP, Client */
@ -155,14 +152,10 @@ void print_client_array();
void print_client_entry(client entry); void print_client_entry(client entry);
void *remove_client_array_thread(void *arg);
ap insert_to_ap_array(ap entry); ap insert_to_ap_array(ap entry);
void print_ap_array(); void print_ap_array();
void *remove_ap_array_thread(void *arg);
ap ap_array_get_ap(uint8_t bssid_addr[]); ap ap_array_get_ap(uint8_t bssid_addr[]);
/* Utils */ /* Utils */

View file

@ -1,56 +1,28 @@
#include <libubus.h> #include <libubus.h>
#include <stdio.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <syslog.h>
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include "datastorage.h" #include "datastorage.h"
#include "networksocket.h" #include "networksocket.h"
#include "ubus.h" #include "ubus.h"
#include "dawn_uci.h" #include "dawn_uci.h"
#include "rssi.h" #include "crypto.h"
#define BUFSIZE 17 #define BUFSIZE 17
#define BUFSIZE_DIR 256 #define BUFSIZE_DIR 256
#include "crypto.h"
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
//static void* (*real_malloc)(size_t)=NULL;
//static void* (*real_free)(void *p)=NULL;
void daemon_shutdown(); void daemon_shutdown();
void signal_handler(int sig); void signal_handler(int sig);
struct sigaction newSigAction; struct sigaction newSigAction;
pthread_t tid_probe;
pthread_t tid_client;
//pthread_t tid_get_client;
//pthread_t tid_update_hostapd_socks;
pthread_t tid_kick_clients;
pthread_t tid_ap;
void daemon_shutdown() { void daemon_shutdown() {
// kill threads // kill threads
printf("Cancelling Threads!\n"); printf("Cancelling Threads!\n");
// pthread_cancel(tid_probe); uloop_cancelled = true;
// pthread_cancel(tid_client);
//pthread_cancel(tid_get_client);
//pthread_cancel(tid_update_hostapd_socks);
// free ressources // free ressources
printf("Freeing mutex ressources\n"); printf("Freeing mutex ressources\n");
@ -58,25 +30,19 @@ void daemon_shutdown() {
pthread_mutex_destroy(&probe_array_mutex); pthread_mutex_destroy(&probe_array_mutex);
pthread_mutex_destroy(&client_array_mutex); pthread_mutex_destroy(&client_array_mutex);
pthread_mutex_destroy(&ap_array_mutex); pthread_mutex_destroy(&ap_array_mutex);
//printf("Free Counter: %d\n", free_counter);
} }
void signal_handler(int sig) { void signal_handler(int sig) {
printf("SOME SIGNAL RECEIVED!\n"); printf("SOME SIGNAL RECEIVED!\n");
switch (sig) { switch (sig) {
case SIGHUP: case SIGHUP:
//syslog(LOG_WARNING, "Received SIGHUP signal.");
break; break;
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
//syslog(LOG_INFO, "Daemon exiting");
//daemonShutdown();
daemon_shutdown(); daemon_shutdown();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
default: default:
//syslog(LOG_WARNING, "Unhandled signal %s", strsignal(sig));
break; break;
} }
} }
@ -171,11 +137,6 @@ int main(int argc, char **argv) {
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1);
//pthread_create(&tid_probe, NULL, &remove_probe_array_thread, (void *) &time_config.remove_probe);
//pthread_create(&tid_client, NULL, &remove_client_array_thread, (void *) &time_config.remove_client);
//pthread_create(&tid_get_client, NULL, &update_clients_thread, (void *) &time_config.update_client);
//pthread_create(&tid_update_hostapd_socks, NULL, &update_hostapd_sockets, &time_config.update_hostapd);
dawn_init_ubus(ubus_socket, opt_hostapd_dir); dawn_init_ubus(ubus_socket, opt_hostapd_dir);
return 0; return 0;

View file

@ -565,19 +565,6 @@ void uloop_add_data_cbs()
uloop_timeout_add(&ap_timeout); uloop_timeout_add(&ap_timeout);
} }
void *remove_probe_array_thread(void *arg) {
printf("Removing thread with time: %lu\n", *(long int *) arg);
time_t time_treshold = *(time_t *) arg;
while (1) {
sleep(time_treshold);
pthread_mutex_lock(&probe_array_mutex);
printf("[Thread] : Removing old entries!\n");
remove_old_probe_entries(time(0), time_treshold);
pthread_mutex_unlock(&probe_array_mutex);
}
return 0;
}
void remove_probe_array_cb(struct uloop_timeout *t) { void remove_probe_array_cb(struct uloop_timeout *t) {
pthread_mutex_lock(&probe_array_mutex); pthread_mutex_lock(&probe_array_mutex);
printf("[Thread] : Removing old entries!\n"); printf("[Thread] : Removing old entries!\n");
@ -586,19 +573,6 @@ void remove_probe_array_cb(struct uloop_timeout *t) {
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000); uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
} }
void *remove_client_array_thread(void *arg) {
time_t time_treshold_client = *(time_t *) arg;
printf("Removing client thread with time: %lu\n", time_treshold_client);
while (1) {
sleep(time_treshold_client);
pthread_mutex_lock(&client_array_mutex);
printf("[Thread] : Removing old client entries!\n");
remove_old_client_entries(time(0), time_treshold_client);
pthread_mutex_unlock(&client_array_mutex);
}
return 0;
}
void remove_client_array_cb(struct uloop_timeout *t) void remove_client_array_cb(struct uloop_timeout *t)
{ {
pthread_mutex_lock(&client_array_mutex); pthread_mutex_lock(&client_array_mutex);
@ -608,19 +582,6 @@ void remove_client_array_cb(struct uloop_timeout *t)
uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000); uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000);
} }
void *remove_ap_array_thread(void *arg) {
time_t time_treshold_ap = *(time_t *) arg;
printf("Removing ap thread with time: %lu\n", time_treshold_ap);
while (1) {
sleep(time_treshold_ap);
pthread_mutex_lock(&ap_array_mutex);
printf("[Thread] : Removing old ap entries!\n");
remove_old_ap_entries(time(0), time_treshold_ap);
pthread_mutex_unlock(&ap_array_mutex);
}
return 0;
}
void remove_ap_array_cb(struct uloop_timeout *t) { void remove_ap_array_cb(struct uloop_timeout *t) {
pthread_mutex_lock(&ap_array_mutex); pthread_mutex_lock(&ap_array_mutex);
printf("[ULOOP] : Removing old ap entries!\n"); printf("[ULOOP] : Removing old ap entries!\n");

View file

@ -18,7 +18,6 @@
static struct ubus_context *ctx = NULL; static struct ubus_context *ctx = NULL;
static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */ static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */
//static struct ubus_context *ctx_hostapd;
static struct ubus_subscriber hostapd_event; static struct ubus_subscriber hostapd_event;
static struct blob_buf b; static struct blob_buf b;
@ -464,7 +463,6 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) {
uloop_timeout_add(&hostapd_timer); uloop_timeout_add(&hostapd_timer);
// remove probe // remove probe
//uloop_timeout_add(&probe_timeout);
uloop_add_data_cbs(); uloop_add_data_cbs();
// get clients // get clients