summaryrefslogtreecommitdiff
path: root/src/ipcpd/unicast/pol/link_state.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2021-06-21 20:24:03 +0200
committerSander Vrijders <[email protected]>2021-06-23 08:36:48 +0200
commit8ca960fa0274018cb4f94a1826029d74e6f762e0 (patch)
tree268ffb6b24027d65c738a8edd196a1ed52134fcc /src/ipcpd/unicast/pol/link_state.c
parentac53f8ea09b9a24321bc2c00832ba8a117115134 (diff)
downloadouroboros-8ca960fa0274018cb4f94a1826029d74e6f762e0.tar.gz
ouroboros-8ca960fa0274018cb4f94a1826029d74e6f762e0.zip
lib, ipcpd, irmd: Wrap pthread unlocks for cleanup
This add an ouroboros/pthread.h header that wraps the pthread_..._unlock() functions for cleanup using pthread_cleanup_push() as this casting is not safe (and there were definitely bad casts in the code). The close() function is now also wrapped for cleanup in ouroboros/sockets.h. This allows enabling more compiler checks. Signed-off-by: Dimitri Staessens <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/ipcpd/unicast/pol/link_state.c')
-rw-r--r--src/ipcpd/unicast/pol/link_state.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/ipcpd/unicast/pol/link_state.c b/src/ipcpd/unicast/pol/link_state.c
index e8983ec6..cca85d63 100644
--- a/src/ipcpd/unicast/pol/link_state.c
+++ b/src/ipcpd/unicast/pol/link_state.c
@@ -38,6 +38,7 @@
#include <ouroboros/list.h>
#include <ouroboros/logs.h>
#include <ouroboros/notifier.h>
+#include <ouroboros/pthread.h>
#include <ouroboros/rib.h>
#include <ouroboros/utils.h>
@@ -52,7 +53,6 @@
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
-#include <pthread.h>
#define RECALC_TIME 4
#define LS_UPDATE_TIME 15
@@ -648,8 +648,7 @@ static void * lsupdate(void * o)
pthread_rwlock_wrlock(&ls.db_lock);
- pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock,
- (void *) &ls.db_lock);
+ pthread_cleanup_push(__cleanup_rwlock_unlock, &ls.db_lock);
list_for_each_safe(p, h, &ls.db) {
struct adjacency * adj;
@@ -709,8 +708,7 @@ static void forward_lsm(uint8_t * buf,
pthread_rwlock_rdlock(&ls.db_lock);
- pthread_cleanup_push((void (*))(void *) pthread_rwlock_unlock,
- &ls.db_lock);
+ pthread_cleanup_push(__cleanup_rwlock_unlock, &ls.db_lock);
list_for_each(p, &ls.nbs) {
struct nb * nb = list_entry(p, struct nb, next);
@@ -721,6 +719,11 @@ static void forward_lsm(uint8_t * buf,
pthread_cleanup_pop(true);
}
+static void cleanup_fqueue(void * fq)
+{
+ fqueue_destroy((fqueue_t *) fq);
+}
+
static void * lsreader(void * o)
{
fqueue_t * fq;
@@ -739,8 +742,7 @@ static void * lsreader(void * o)
if (fq == NULL)
return (void *) -1;
- pthread_cleanup_push((void (*) (void *)) fqueue_destroy,
- (void *) fq);
+ pthread_cleanup_push(cleanup_fqueue, fq);
while (true) {
ret = fevent(ls.mgmt_set, fq, NULL);
@@ -813,8 +815,7 @@ static void handle_event(void * self,
case NOTIFY_DT_CONN_ADD:
pthread_rwlock_rdlock(&ls.db_lock);
- pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock,
- (void *) &ls.db_lock);
+ pthread_cleanup_push(__cleanup_rwlock_unlock, &ls.db_lock);
send_lsm(ipcpi.dt_addr, c->conn_info.addr, 0);
pthread_cleanup_pop(true);