diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-05 16:03:35 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-05 16:03:35 +0100 |
| commit | 2a7bc3f8a7cd232cad0a858b4d810a2cac3193d8 (patch) | |
| tree | 068ba4de5c5672bafea62f85a56fde788bbd23c6 /src | |
| parent | 4e0b179014ced8c16c90bdfd6d82df625fea47e9 (diff) | |
Read the accesslist before any consumer consults it
Diffstat (limited to 'src')
| -rw-r--r-- | src/ot_accesslist.c | 16 | ||||
| -rw-r--r-- | src/ot_accesslist.h | 5 |
2 files changed, 11 insertions, 10 deletions
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; | |||
| 33 | const char *g_accesslist_pipe_add = NULL; | 33 | const char *g_accesslist_pipe_add = NULL; |
| 34 | const char *g_accesslist_pipe_delete = NULL; | 34 | const char *g_accesslist_pipe_delete = NULL; |
| 35 | #endif | 35 | #endif |
| 36 | static pthread_mutex_t g_accesslist_mutex; | 36 | static pthread_mutex_t g_accesslist_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 37 | 37 | ||
| 38 | /* Accesslists are lock free linked lists. We can not make them locking, because every announce | 38 | /* Accesslists are lock free linked lists. We can not make them locking, because every announce |
| 39 | would try to acquire the mutex, making it the most contested mutex in the whole of opentracker, | 39 | 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) { | |||
| 257 | (void)args; | 257 | (void)args; |
| 258 | 258 | ||
| 259 | while (1) { | 259 | while (1) { |
| 260 | /* Wait for signals */ | ||
| 261 | while (sigwait(&signal_mask, &sig) != 0) | ||
| 262 | ; | ||
| 263 | |||
| 260 | if (!g_opentracker_running) | 264 | if (!g_opentracker_running) |
| 261 | return NULL; | 265 | return NULL; |
| 262 | 266 | ||
| 263 | /* Initial attempt to read accesslist */ | ||
| 264 | accesslist_readfile(); | 267 | accesslist_readfile(); |
| 265 | |||
| 266 | /* Wait for signals */ | ||
| 267 | while (sigwait(&signal_mask, &sig) != 0 && sig != SIGHUP) | ||
| 268 | ; | ||
| 269 | } | 268 | } |
| 270 | return NULL; | 269 | return NULL; |
| 271 | } | 270 | } |
| @@ -405,7 +404,9 @@ static void accesslist_stop_fifo_worker(pthread_t thread, _Atomic int *left, con | |||
| 405 | 404 | ||
| 406 | static pthread_t thread_id; | 405 | static pthread_t thread_id; |
| 407 | void accesslist_init(void) { | 406 | void accesslist_init(void) { |
| 408 | pthread_mutex_init(&g_accesslist_mutex, NULL); | 407 | /* Everything that consults the list starts after this returns */ |
| 408 | accesslist_readfile(); | ||
| 409 | |||
| 409 | pthread_create(&thread_id, NULL, accesslist_worker, NULL); | 410 | pthread_create(&thread_id, NULL, accesslist_worker, NULL); |
| 410 | #ifdef WANT_DYNAMIC_ACCESSLIST | 411 | #ifdef WANT_DYNAMIC_ACCESSLIST |
| 411 | if (g_accesslist_pipe_add) | 412 | if (g_accesslist_pipe_add) |
| @@ -436,7 +437,6 @@ void accesslist_deinit(void) { | |||
| 436 | #endif | 437 | #endif |
| 437 | 438 | ||
| 438 | pthread_mutex_unlock(&g_accesslist_mutex); | 439 | pthread_mutex_unlock(&g_accesslist_mutex); |
| 439 | pthread_mutex_destroy(&g_accesslist_mutex); | ||
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | void accesslist_cleanup(void) { | 442 | 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 @@ | |||
| 12 | 12 | ||
| 13 | #if defined(WANT_ACCESSLIST_BLACK) || defined(WANT_ACCESSLIST_WHITE) | 13 | #if defined(WANT_ACCESSLIST_BLACK) || defined(WANT_ACCESSLIST_WHITE) |
| 14 | #define WANT_ACCESSLIST | 14 | #define WANT_ACCESSLIST |
| 15 | /* Starts a thread that rereads the list when sent SIGHUP, and is stopped by | 15 | /* Reads the list, then starts a thread that rereads it when sent SIGHUP and |
| 16 | being sent one, so the caller blocks SIGHUP process wide beforehand */ | 16 | is stopped by being sent one, so the caller blocks SIGHUP process wide |
| 17 | beforehand */ | ||
| 17 | void accesslist_init(void); | 18 | void accesslist_init(void); |
| 18 | void accesslist_deinit(void); | 19 | void accesslist_deinit(void); |
| 19 | int accesslist_hashisvalid(const ot_hash hash); | 20 | int accesslist_hashisvalid(const ot_hash hash); |
