From ccc187ff5e6cbc411476c5f5e68cc6bb1fe35818 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 3 Mar 2014 12:20:41 +0100 Subject: [PATCH] pthreadpool: Fix pthreadpools with fork The current could would crash if a pthreadpool was created, deleted and the process then fork()s. "pthreadpools" is NULL in this case, but the pthread_atfork handlers are in place. This fixes walking the pthreadpools list in reverse. Signed-off-by: Volker Lendecke Reviewed-by: Kamen Mazdrashki Reviewed-by: Simo Sorce Reviewed-by: Michael Adam --- source3/lib/pthreadpool/pthreadpool.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/source3/lib/pthreadpool/pthreadpool.c b/source3/lib/pthreadpool/pthreadpool.c index bd58d62f8fa..654d420732f 100644 --- a/source3/lib/pthreadpool/pthreadpool.c +++ b/source3/lib/pthreadpool/pthreadpool.c @@ -188,16 +188,11 @@ static void pthreadpool_parent(void) int ret; struct pthreadpool *pool; - pool = DLIST_TAIL(pthreadpools); - - while (1) { + for (pool = DLIST_TAIL(pthreadpools); + pool != NULL; + pool = DLIST_PREV(pool)) { ret = pthread_mutex_unlock(&pool->mutex); assert(ret == 0); - - if (pool == pthreadpools) { - break; - } - pool = pool->prev; } ret = pthread_mutex_unlock(&pthreadpools_mutex); @@ -209,9 +204,10 @@ static void pthreadpool_child(void) int ret; struct pthreadpool *pool; - pool = DLIST_TAIL(pthreadpools); + for (pool = DLIST_TAIL(pthreadpools); + pool != NULL; + pool = DLIST_PREV(pool)) { - while (1) { close(pool->sig_pipe[0]); close(pool->sig_pipe[1]); @@ -236,11 +232,6 @@ static void pthreadpool_child(void) ret = pthread_mutex_unlock(&pool->mutex); assert(ret == 0); - - if (pool == pthreadpools) { - break; - } - pool = pool->prev; } ret = pthread_mutex_unlock(&pthreadpools_mutex); -- 2.11.4.GIT