From e42a24f39afe15c5ac579fa519df98643d4fc6dd Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sun, 21 Jun 2026 12:46:27 +0200 Subject: lib: Guard logging against thread cancellation POSIX defines printf() and syslog() as possible cancellation points. This hardens thread cancellation cleanup by wrapping the log macros in pthread_setcancelstate(PTHREAD_CANCEL_DISABLE) and restores the prior cancel state afterwards. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- include/ouroboros/logs.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/ouroboros/logs.h b/include/ouroboros/logs.h index 58494531..1ae77673 100644 --- a/include/ouroboros/logs.h +++ b/include/ouroboros/logs.h @@ -29,6 +29,7 @@ #include +#include #include #include #include @@ -55,6 +56,8 @@ void log_fini(void); #define __olog(CLR, LVL, SYSLVL, ...) \ do { \ + int __cs; \ + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &__cs); \ if (log_syslog) { \ syslog(SYSLVL, __VA_ARGS__); \ } else { \ @@ -64,10 +67,13 @@ void log_fini(void); printf(CLR_RESET "\n"); \ fflush(stdout); \ } \ + pthread_setcancelstate(__cs, NULL); \ } while (0) #define __olog_id(CLR, LVL, SYSLVL, id, fmt, ...) \ do { \ + int __cs; \ + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &__cs); \ if (log_syslog) { \ syslog(SYSLVL, "[" HASH_FMT64 "] " fmt, \ HASH_VAL64(id), ## __VA_ARGS__); \ @@ -79,6 +85,7 @@ void log_fini(void); printf(CLR_RESET "\n"); \ fflush(stdout); \ } \ + pthread_setcancelstate(__cs, NULL); \ } while (0) #ifndef OUROBOROS_DISABLE_LOGGING -- cgit v1.2.3