summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_accesslist.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index 724978e..4bf1701 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -160,6 +160,9 @@ static void accesslist_readfile(void) {
160 const char *map; 160 const char *map;
161 size_t maplen, capacity, found; 161 size_t maplen, capacity, found;
162 162
163 if (!g_accesslist_filename)
164 return;
165
163 if (accesslist_map(g_accesslist_filename, &map, &maplen) < 0) { 166 if (accesslist_map(g_accesslist_filename, &map, &maplen) < 0) {
164 char *wd = getcwd(NULL, 0); 167 char *wd = getcwd(NULL, 0);
165 fprintf(stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd); 168 fprintf(stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd);
@@ -185,7 +188,8 @@ static void accesslist_readfile(void) {
185 if (map) 188 if (map)
186 munmap((void *)map, maplen); 189 munmap((void *)map, maplen);
187 190
188 qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash); 191 if (found)
192 qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash);
189 accesslist_new->size = found; 193 accesslist_new->size = found;
190 194
191 /* Now exchange the accesslist vector in the least race condition prone way */ 195 /* Now exchange the accesslist vector in the least race condition prone way */
@@ -223,18 +227,18 @@ int accesslist_hashisvalid(const ot_hash hash) {
223#endif 227#endif
224 void *exactmatch = NULL; 228 void *exactmatch = NULL;
225 229
226 if (accesslist) 230 if (accesslist && accesslist->size)
227 exactmatch = bsearch(hash, accesslist->list, accesslist->size, OT_HASH_COMPARE_SIZE, vector_compare_hash); 231 exactmatch = bsearch(hash, accesslist->list, accesslist->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
228 232
229#ifdef WANT_DYNAMIC_ACCESSLIST 233#ifdef WANT_DYNAMIC_ACCESSLIST
230 /* If we had no match on the main list, scan the list of dynamically added hashes */ 234 /* If we had no match on the main list, scan the list of dynamically added hashes */
231 accesslist_add = g_accesslist_add; 235 accesslist_add = g_accesslist_add;
232 if ((exactmatch == NULL) && accesslist_add) 236 if ((exactmatch == NULL) && accesslist_add && accesslist_add->size)
233 exactmatch = bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash); 237 exactmatch = bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
234 238
235 /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */ 239 /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */
236 accesslist_delete = g_accesslist_delete; 240 accesslist_delete = g_accesslist_delete;
237 if ((exactmatch != NULL) && accesslist_delete && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash)) 241 if ((exactmatch != NULL) && accesslist_delete && accesslist_delete->size && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash))
238 exactmatch = NULL; 242 exactmatch = NULL;
239#endif 243#endif
240 244
@@ -384,8 +388,9 @@ void accesslist_init(void) {
384} 388}
385 389
386void accesslist_deinit(void) { 390void accesslist_deinit(void) {
387 /* Wake up sleeping worker */ 391 /* Wake the worker and wait for it to notice that the tracker is stopping. */
388 pthread_kill(thread_id, SIGHUP); 392 pthread_kill(thread_id, SIGHUP);
393 pthread_join(thread_id, NULL);
389 394
390 pthread_mutex_lock(&g_accesslist_mutex); 395 pthread_mutex_lock(&g_accesslist_mutex);
391 396
@@ -397,7 +402,6 @@ void accesslist_deinit(void) {
397#endif 402#endif
398 403
399 pthread_mutex_unlock(&g_accesslist_mutex); 404 pthread_mutex_unlock(&g_accesslist_mutex);
400 pthread_cancel(thread_id);
401 pthread_mutex_destroy(&g_accesslist_mutex); 405 pthread_mutex_destroy(&g_accesslist_mutex);
402} 406}
403 407