diff --git a/src/api/socket.c b/src/api/socket.c index 1314b9393..0f3b65541 100644 --- a/src/api/socket.c +++ b/src/api/socket.c @@ -263,7 +263,6 @@ void listen_telnet(const enum telnet_type type) for(unsigned int i = 0; i < MAX_API_THREADS; i++) { // Spawn telnet thread - pthread_t telnet_connection_thread; // Create a private copy of the socket fd for the child thread struct thread_info *tinfo = calloc(1, sizeof(struct thread_info)); if(!tinfo) @@ -273,7 +272,7 @@ void listen_telnet(const enum telnet_type type) tinfo->tid = i; tinfo->istelnet = (type == TELNETv4 || type == TELNETv6); tinfo->stype = stype; - if(pthread_create(&telnet_connection_thread, &attr, telnet_connection_handler_thread, (void*) tinfo) != 0) + if(pthread_create(&api_threads[i], &attr, telnet_connection_handler_thread, (void*) tinfo) != 0) { // Log the error code description logg("WARNING: Unable to open telnet processing thread: %s", strerror(errno)); diff --git a/src/daemon.c b/src/daemon.c index 9ba11f06c..968902177 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -29,7 +29,7 @@ #include pthread_t threads[THREADS_MAX] = { 0 }; -pthread_t api_threads[TELNET_MAX][MAX_API_THREADS] = {{ 0 }}; +pthread_t api_threads[MAX_API_THREADS] = { 0 }; bool resolver_ready = false; void go_daemon(void) @@ -268,18 +268,16 @@ void cleanup(const int ret) // Do proper cleanup only if FTL started successfully if(resolver_ready) { + // Terminate threads terminate_threads(); // Cancel and join possibly still running API worker threads - for(enum telnet_type tt = 0; tt < TELNET_MAX; tt++) + for(unsigned int tid = 0; tid < MAX_API_THREADS; tid++) { - for(unsigned int tid = 0; tid < MAX_API_THREADS; tid++) - { - // Otherwise, cancel and join the thread - logg("Joining API worker thread %d/%d", tt,tid); - pthread_cancel(api_threads[tt][tid]); - pthread_join(api_threads[tt][tid], NULL); - } + // Otherwise, cancel and join the thread + logg("Joining API worker thread %d", tid); + pthread_cancel(api_threads[tid]); + pthread_join(api_threads[tid], NULL); } // Close database connection diff --git a/src/daemon.h b/src/daemon.h index edcd9227b..cc91dd4da 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -13,7 +13,7 @@ #include "enums.h" extern pthread_t threads[THREADS_MAX]; #define MAX_API_THREADS 5 -extern pthread_t api_threads[TELNET_MAX][MAX_API_THREADS]; +extern pthread_t api_threads[MAX_API_THREADS]; void go_daemon(void); void savepid(void);