From b493ff0b2497a3b01409ef603189e65a6f36eea3 Mon Sep 17 00:00:00 2001 From: Steve Dickson Date: Mon, 18 Jan 2016 09:12:41 -0500 Subject: gssd: Try to join a terminated thread after a short wait. Use pthread_timedjoin_np() to try to join to a terminated thread. If successful return 0 otherwise return 1 which tells the caller it should do the join Signed-off-by: Steve Dickson --- utils/gssd/gssd.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c index 3c425ce..844a7ae 100644 --- a/utils/gssd/gssd.c +++ b/utils/gssd/gssd.c @@ -65,6 +65,7 @@ #include #include #include +#include #include "gssd.h" #include "err_util.h" @@ -361,6 +362,28 @@ gssd_destroy_client(struct clnt_info *clp) static void gssd_scan(void); +#define JOIN_TIMOUT 1 + +/* + * Try to join a terminated thread after a short wait. + * If successful return 0 otherwise return 1 which + * tells the caller it should do the join. + */ +static int gssd_try_join(pthread_t th) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_REALTIME, &ts) < 0) { + printerr(1, "clock_gettime failed: %s\n", strerror(errno)); + return 1; + } + ts.tv_sec += JOIN_TIMOUT; + if (pthread_timedjoin_np(th, NULL, &ts) == 0) + return 0; + + printerr(2, "gssd_try_join: no join\n"); + return 1; +} static void gssd_clnt_gssd_cb(int UNUSED(fd), short UNUSED(which), void *data) { @@ -373,7 +396,8 @@ gssd_clnt_gssd_cb(int UNUSED(fd), short UNUSED(which), void *data) printerr(0, "pthread_create failed: ret %d: %s\n", ret, strerror(errno)); return; } - pthread_join(th, NULL); + if (gssd_try_join(th)) + pthread_join(th, NULL); } static void @@ -388,7 +412,8 @@ gssd_clnt_krb5_cb(int UNUSED(fd), short UNUSED(which), void *data) printerr(0, "pthread_create failed: ret %d: %s\n", ret, strerror(errno)); } - pthread_join(th, NULL); + if (gssd_try_join(th)) + pthread_join(th, NULL); } static struct clnt_info * -- cgit v1.2.1