diff options
author | Dimitri Staessens <[email protected]> | 2021-06-21 20:24:03 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2021-06-23 08:36:48 +0200 |
commit | 8ca960fa0274018cb4f94a1826029d74e6f762e0 (patch) | |
tree | 268ffb6b24027d65c738a8edd196a1ed52134fcc /src/ipcpd/udp | |
parent | ac53f8ea09b9a24321bc2c00832ba8a117115134 (diff) | |
download | ouroboros-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/udp')
-rw-r--r-- | src/ipcpd/udp/main.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c index 13db0c1f..03de24ab 100644 --- a/src/ipcpd/udp/main.c +++ b/src/ipcpd/udp/main.c @@ -39,6 +39,7 @@ #include <ouroboros/fqueue.h> #include <ouroboros/errno.h> #include <ouroboros/logs.h> +#include <ouroboros/pthread.h> #include "ipcp.h" #include "shim-data.h" @@ -51,7 +52,6 @@ #include <netinet/in.h> #include <signal.h> #include <stdlib.h> -#include <pthread.h> #include <sys/wait.h> #include <fcntl.h> @@ -393,8 +393,7 @@ static void * ipcp_udp_mgmt_handler(void * o) { (void) o; - pthread_cleanup_push((void (*)(void *)) pthread_mutex_unlock, - (void *) &udp_data.mgmt_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &udp_data.mgmt_lock); while (true) { struct mgmt_frame * frame; @@ -485,9 +484,14 @@ static void * ipcp_udp_packet_reader(void * o) return 0; } -static void cleanup_writer(void * o) +static void cleanup_fqueue(void * fq) { - fqueue_destroy((fqueue_t *) o); + fqueue_destroy((fqueue_t *) fq); +} + +static void cleanup_sdb(void * sdb) +{ + ipcp_sdb_release((struct shm_du_buff *) sdb); } static void * ipcp_udp_packet_writer(void * o) @@ -502,7 +506,7 @@ static void * ipcp_udp_packet_writer(void * o) ipcp_lock_to_core(); - pthread_cleanup_push(cleanup_writer, fq); + pthread_cleanup_push(cleanup_fqueue, fq); while (true) { struct sockaddr_in saddr; @@ -545,8 +549,7 @@ static void * ipcp_udp_packet_writer(void * o) memcpy(buf, &eid, sizeof(eid)); - pthread_cleanup_push((void (*)(void *)) - ipcp_sdb_release, (void *) sdb); + pthread_cleanup_push(cleanup_sdb, sdb); if (sendto(udp_data.s_fd, buf, len + OUR_HEADER_LEN, MSG_CONFIRM, |