From 8ca960fa0274018cb4f94a1826029d74e6f762e0 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 21 Jun 2021 20:24:03 +0200 Subject: 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 Signed-off-by: Sander Vrijders --- src/ipcpd/ipcp.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/ipcpd/ipcp.c') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 8c9d3525..56cdb5d2 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -54,6 +54,7 @@ #include #include #include +#include #include "ipcp.h" @@ -207,11 +208,6 @@ static struct rib_ops r_ops = { .getattr = ipcp_stat_getattr }; -static void close_ptr(void * o) -{ - close(*((int *) o)); -} - static void * acceptloop(void * o) { int csockfd; @@ -239,7 +235,7 @@ static void * acceptloop(void * o) break; } - pthread_cleanup_push(close_ptr, &csockfd); + pthread_cleanup_push(__cleanup_close_ptr, &csockfd); pthread_cleanup_push(free, cmd); cmd->len = read(csockfd, cmd->cbuf, SOCK_BUF_SIZE); @@ -295,8 +291,7 @@ static void * mainloop(void * o) pthread_mutex_lock(&ipcpi.cmd_lock); - pthread_cleanup_push((void *)(void *) pthread_mutex_unlock, - &ipcpi.cmd_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &ipcpi.cmd_lock); while (list_is_empty(&ipcpi.cmds)) pthread_cond_wait(&ipcpi.cmd_cond, &ipcpi.cmd_lock); @@ -318,7 +313,7 @@ static void * mainloop(void * o) tpm_dec(ipcpi.tpm); - pthread_cleanup_push(close_ptr, &sfd); + pthread_cleanup_push(__cleanup_close_ptr, &sfd); pthread_cleanup_push(free_msg, msg); switch (msg->code) { @@ -665,7 +660,7 @@ static void * mainloop(void * o) ipcp_msg__pack(&ret_msg, buffer.data); - pthread_cleanup_push(close_ptr, &sfd); + pthread_cleanup_push(__cleanup_close_ptr, &sfd); if (write(sfd, buffer.data, buffer.len) == -1) log_warn("Failed to send reply message"); @@ -955,8 +950,7 @@ int ipcp_wait_state(enum ipcp_state state, pthread_mutex_lock(&ipcpi.state_mtx); - pthread_cleanup_push((void *)(void *) pthread_mutex_unlock, - &ipcpi.state_mtx); + pthread_cleanup_push(__cleanup_mutex_unlock, &ipcpi.state_mtx); while (ipcpi.state != state && ipcpi.state != IPCP_SHUTDOWN -- cgit v1.2.3