[PATCH v2 1/2] Do not try to kill thread that was successfully joined
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[PATCH v2 1/2] Do not try to kill thread that was successfully joined
- From: Consus <consus [at] ftml.net>
- To: nss-pam-ldapd-users [at] lists.arthurdejong.org
- Subject: [PATCH v2 1/2] Do not try to kill thread that was successfully joined
- Date: Sat, 29 Jun 2024 09:53:10 +0300
Calling pthread_kill() after a successfull call pthread_timedjoin_np()
is considered a UB because pthread_t object is no longer valid. This
results in SIGSEGV at least on musl libc.
---
nslcd/nslcd.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c
index d54e2db..2f52e01 100644
--- a/nslcd/nslcd.c
+++ b/nslcd/nslcd.c
@@ -927,10 +927,16 @@ int main(int argc, char *argv[])
for (i = 0; i < nslcd_cfg->threads; i++)
{
#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
- pthread_timedjoin_np(nslcd_threads[i], NULL, &ts);
-#endif /* HAVE_PTHREAD_TIMEDJOIN_NP */
+ if (pthread_timedjoin_np(nslcd_threads[i], NULL, &ts) == -1) {
+ if (errno != EBUSY)
+ log_log(LOG_ERR, "thread %d cannot be joined (ignoring): %s", i,
+ strerror(errno));
+ log_log(LOG_ERR, "thread %d is still running, shutting down anyway", i);
+ }
+#else
if (pthread_kill(nslcd_threads[i], 0) == 0)
log_log(LOG_ERR, "thread %d is still running, shutting down anyway", i);
+#endif /* HAVE_PTHREAD_TIMEDJOIN_NP */
}
/* we're done */
return EXIT_SUCCESS;
--
2.45.2