From 74ee0344a7075bd4d77908989b3ad07244b60d30 Mon Sep 17 00:00:00 2001 From: InterLinked1 <24227567+InterLinked1@users.noreply.github.com> Date: Sat, 30 Nov 2024 10:14:06 -0500 Subject: [PATCH] thread.c: Add log message before calling pthread_cancel. Add a log message *before* calling pthread_cancel, so if a deadlock occurs and this is possibly suspected to be related to pthread_cancel usage, that can be confirmed more easily from the logs (see LBBS-86). --- bbs/thread.c | 8 ++++++++ include/bbs.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/bbs/thread.c b/bbs/thread.c index a8d2aff..6e458a9 100644 --- a/bbs/thread.c +++ b/bbs/thread.c @@ -253,6 +253,14 @@ int bbs_pthread_cancel_kill(pthread_t thread) { int res; + /* Log a message before calling pthread_cancel, since this is dangerous. + * In the unlikely event that a thread is cancelled while in a critical section, + * deadlock could ensue. I've suspected this might have been responsible for + * some issues in the past but few clues have been available to such activity, + * so this log message is an important clue if that happens (see [LBBS-86]). */ + bbs_debug(1, "Attempting to cancel thread %lu\n", (unsigned long) thread); + +#undef pthread_cancel res = pthread_cancel(thread); if (res) { if (res == ESRCH) { diff --git a/include/bbs.h b/include/bbs.h index 1df26d1..8e1180e 100644 --- a/include/bbs.h +++ b/include/bbs.h @@ -89,6 +89,8 @@ #define ctime(a) Do_not_use_ctime__use_ctime_r #define ptsname(fd) Do_not_use_ptsname__use_ptsname_r #define strncpy(dest, src, size) Do_not_use_strncpy__use_safe_strncpy +/* Prohibit direct usage of dangerous functions */ +#define pthread_cancel(t) Do_not_use_pthread_cancel__use_bbs_pthread_cancel_kill #ifndef BBS_MAIN_FILE /* Allow printf only in bbs.c */