1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-05 12:22:11 +03:00

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 <vl@samba.org>
Reviewed-by: Kamen Mazdrashki <kamenim@samba.org>
Reviewed-by: Simo Sorce <simo@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Volker Lendecke
2014-03-03 12:20:41 +01:00
committed by Michael Adam
parent 925625b528
commit ccc187ff5e

View File

@ -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);