From a1b6cebe14d6e0689655a0c4d06064728cbf1f21 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 11 Oct 2018 14:09:37 +0200 Subject: ipcpd: Take correct lock when updating stats The lock of the wrong fd was taken when updating the stats in the DT component. Signed-off-by: Sander Vrijders Signed-off-by: Dimitri Staessens --- src/ipcpd/normal/dt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c index dc7343f1..54346458 100644 --- a/src/ipcpd/normal/dt.c +++ b/src/ipcpd/normal/dt.c @@ -532,12 +532,14 @@ static void packet_handler(int fd, if (ipcp_flow_write(dt_pci.eid, sdb)) { ipcp_sdb_release(sdb); #ifdef IPCP_FLOW_STATS - pthread_mutex_lock(&dt.stat[dt_pci.eid].lock); + pthread_mutex_lock(&dt.stat[fd].lock); ++dt.stat[fd].rcv_pkt[qc]; dt.stat[fd].rcv_bytes[qc] += len; + pthread_mutex_unlock(&dt.stat[fd].lock); + + pthread_mutex_lock(&dt.stat[dt_pci.eid].lock); ++dt.stat[dt_pci.eid].w_drp_pkt[qc]; dt.stat[dt_pci.eid].w_drp_bytes[qc] += len; - pthread_mutex_unlock(&dt.stat[dt_pci.eid].lock); #endif -- cgit v1.2.3 From ca22ee6c603d3a03cca902d302f4c25e1f5b003e Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 11 Oct 2018 15:58:12 +0200 Subject: ipcpd: Call send_lsm under read lock send_lsm was being called from the event handler as well as from lsupdate. The first one was not being locked properly. Signed-off-by: Sander Vrijders Signed-off-by: Dimitri Staessens --- src/ipcpd/normal/pol/link_state.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index 8db1a9c5..e8677f0d 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -795,7 +795,9 @@ static void handle_event(void * self, if (lsdb_add_link(ipcpi.dt_addr, c->conn_info.addr, 0, &qs)) log_dbg("Failed to add new adjacency to LSDB."); + pthread_rwlock_rdlock(&ls.db_lock); send_lsm(ipcpi.dt_addr, c->conn_info.addr, 0); + pthread_rwlock_unlock(&ls.db_lock); break; case NOTIFY_DT_CONN_DEL: -- cgit v1.2.3 From 558fc46c63d28ce2ffd0abc5c737f49cc185ba82 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 11 Oct 2018 15:56:24 +0200 Subject: lib: Add cleanup function in notifier This adds a cleanup function in the notifier in case it gets cancelled, which is a possibility in some callbacks. Signed-off-by: Sander Vrijders Signed-off-by: Dimitri Staessens --- src/lib/notifier.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/notifier.c b/src/lib/notifier.c index 593a0e70..4f77f2e3 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -75,12 +75,15 @@ void notifier_event(int event, pthread_rwlock_rdlock(¬ifier.lock); + pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock, + (void *) ¬ifier.lock) + list_for_each(p, ¬ifier.listeners) { struct listener * l = list_entry(p, struct listener, next); l->callback(l->obj, event, o); } - pthread_rwlock_unlock(¬ifier.lock); + pthread_cleanup_pop(true); } int notifier_reg(notifier_fn_t callback, -- cgit v1.2.3