Skip to content

Commit ed4041c

Browse files
heroin-moosearthurdejong
authored andcommitted
Do not try to kill thread that was successfully joined
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.
1 parent cced213 commit ed4041c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

nslcd/nslcd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,16 @@ int main(int argc, char *argv[])
927927
for (i = 0; i < nslcd_cfg->threads; i++)
928928
{
929929
#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
930-
pthread_timedjoin_np(nslcd_threads[i], NULL, &ts);
931-
#endif /* HAVE_PTHREAD_TIMEDJOIN_NP */
930+
if (pthread_timedjoin_np(nslcd_threads[i], NULL, &ts) == -1) {
931+
if (errno != EBUSY)
932+
log_log(LOG_ERR, "thread %d cannot be joined (ignoring): %s", i,
933+
strerror(errno));
934+
log_log(LOG_ERR, "thread %d is still running, shutting down anyway", i);
935+
}
936+
#else
932937
if (pthread_kill(nslcd_threads[i], 0) == 0)
933938
log_log(LOG_ERR, "thread %d is still running, shutting down anyway", i);
939+
#endif /* HAVE_PTHREAD_TIMEDJOIN_NP */
934940
}
935941
/* we're done */
936942
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)