From 0df9186d8d6248ecc3a82094b8cac9262287c704 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sun, 8 Mar 2020 14:24:55 +0100 Subject: ipcpd: Fix locking in link_state policy There were updates under rdlock instead of wrlock, causing data races and trouble. Also speeds up shutdown a bit. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/pol/link_state.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ipcpd/unicast/pol/link_state.c b/src/ipcpd/unicast/pol/link_state.c index 5360f556..d9482876 100644 --- a/src/ipcpd/unicast/pol/link_state.c +++ b/src/ipcpd/unicast/pol/link_state.c @@ -646,7 +646,7 @@ static void * lsupdate(void * o) while (true) { clock_gettime(CLOCK_REALTIME_COARSE, &now); - pthread_rwlock_rdlock(&ls.db_lock); + pthread_rwlock_wrlock(&ls.db_lock); pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock, (void *) &ls.db_lock); @@ -1015,13 +1015,14 @@ void link_state_fini(void) rib_unreg(LSDB); - pthread_cancel(ls.listener); - pthread_join(ls.listener, NULL); + notifier_unreg(handle_event); + pthread_cancel(ls.listener); pthread_cancel(ls.lsreader); - pthread_join(ls.lsreader, NULL); - pthread_cancel(ls.lsupdate); + + pthread_join(ls.listener, NULL); + pthread_join(ls.lsreader, NULL); pthread_join(ls.lsupdate, NULL); fset_destroy(ls.mgmt_set); @@ -1043,6 +1044,4 @@ void link_state_fini(void) pthread_rwlock_destroy(&ls.db_lock); pthread_mutex_destroy(&ls.routing_i_lock); - - notifier_unreg(handle_event); } -- cgit v1.2.3