From 15ccd8ac0d1a7bfab2db3929200f3926c1e05db2 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 7 Oct 2017 10:06:22 +0200 Subject: ipcpd: Handle cancellation while writing LSAs This adds a cleanup handler to ensure the lock is released in the event that the thread is cancelled during a write. An alternative solution could be to make the flow write in a non-blocking way (only the blocking write contains an execution path that has a cancellation point). Fixes #55 --- src/ipcpd/normal/pol/link_state.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index f3af2771..9c41dba3 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -534,13 +534,16 @@ static void forward_lsm(uint8_t * buf, pthread_rwlock_rdlock(&ls.db_lock); + pthread_cleanup_push((void (*))(void *) pthread_rwlock_unlock, + &ls.db_lock); + list_for_each(p, &ls.nbs) { struct nb * nb = list_entry(p, struct nb, next); if (nb->type == NB_MGMT && nb->fd != in_fd) flow_write(nb->fd, buf, len); } - pthread_rwlock_unlock(&ls.db_lock); + pthread_cleanup_pop(true); } static void * lsreader(void * o) -- cgit v1.2.3