summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-10-07 10:06:22 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-10-07 10:11:00 +0200
commit15ccd8ac0d1a7bfab2db3929200f3926c1e05db2 (patch)
tree2a338353303e270ff0f670e3e4c24fc4d4e8fc07
parent7dcacfbc94386e155650aaaa1a8f56cfb6fc53f9 (diff)
downloadouroboros-15ccd8ac0d1a7bfab2db3929200f3926c1e05db2.tar.gz
ouroboros-15ccd8ac0d1a7bfab2db3929200f3926c1e05db2.zip
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
-rw-r--r--src/ipcpd/normal/pol/link_state.c5
1 files changed, 4 insertions, 1 deletions
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)