From 2a7bc3f8a7cd232cad0a858b4d810a2cac3193d8 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 5 Nov 2026 16:03:35 +0100 Subject: Read the accesslist before any consumer consults it --- src/ot_accesslist.c | 16 ++++++++-------- src/ot_accesslist.h | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ot_accesslist.c b/src/ot_accesslist.c index ea5bdba..0597e9a 100644 --- a/src/ot_accesslist.c +++ b/src/ot_accesslist.c @@ -33,7 +33,7 @@ const char *g_accesslist_filename = NULL; const char *g_accesslist_pipe_add = NULL; const char *g_accesslist_pipe_delete = NULL; #endif -static pthread_mutex_t g_accesslist_mutex; +static pthread_mutex_t g_accesslist_mutex = PTHREAD_MUTEX_INITIALIZER; /* Accesslists are lock free linked lists. We can not make them locking, because every announce would try to acquire the mutex, making it the most contested mutex in the whole of opentracker, @@ -257,15 +257,14 @@ static void *accesslist_worker(void *args) { (void)args; while (1) { + /* Wait for signals */ + while (sigwait(&signal_mask, &sig) != 0) + ; + if (!g_opentracker_running) return NULL; - /* Initial attempt to read accesslist */ accesslist_readfile(); - - /* Wait for signals */ - while (sigwait(&signal_mask, &sig) != 0 && sig != SIGHUP) - ; } return NULL; } @@ -405,7 +404,9 @@ static void accesslist_stop_fifo_worker(pthread_t thread, _Atomic int *left, con static pthread_t thread_id; void accesslist_init(void) { - pthread_mutex_init(&g_accesslist_mutex, NULL); + /* Everything that consults the list starts after this returns */ + accesslist_readfile(); + pthread_create(&thread_id, NULL, accesslist_worker, NULL); #ifdef WANT_DYNAMIC_ACCESSLIST if (g_accesslist_pipe_add) @@ -436,7 +437,6 @@ void accesslist_deinit(void) { #endif pthread_mutex_unlock(&g_accesslist_mutex); - pthread_mutex_destroy(&g_accesslist_mutex); } void accesslist_cleanup(void) { diff --git a/src/ot_accesslist.h b/src/ot_accesslist.h index 68c88dc..c0f3fc2 100644 --- a/src/ot_accesslist.h +++ b/src/ot_accesslist.h @@ -12,8 +12,9 @@ #if defined(WANT_ACCESSLIST_BLACK) || defined(WANT_ACCESSLIST_WHITE) #define WANT_ACCESSLIST -/* Starts a thread that rereads the list when sent SIGHUP, and is stopped by - being sent one, so the caller blocks SIGHUP process wide beforehand */ +/* Reads the list, then starts a thread that rereads it when sent SIGHUP and + is stopped by being sent one, so the caller blocks SIGHUP process wide + beforehand */ void accesslist_init(void); void accesslist_deinit(void); int accesslist_hashisvalid(const ot_hash hash); -- cgit v1.3