From owner-freebsd-threads@FreeBSD.ORG Fri Jan 25 11:00:05 2008 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7053116A418 for ; Fri, 25 Jan 2008 11:00:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6992B13C447 for ; Fri, 25 Jan 2008 11:00:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0PB05RP043839 for ; Fri, 25 Jan 2008 11:00:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0PB05sM043838; Fri, 25 Jan 2008 11:00:05 GMT (envelope-from gnats) Date: Fri, 25 Jan 2008 11:00:05 GMT Message-Id: <200801251100.m0PB05sM043838@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Gary Stanley Cc: Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Gary Stanley List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jan 2008 11:00:05 -0000 The following reply was made to PR threads/119920; it has been noted by GNATS. From: Gary Stanley To: bug-followup@FreeBSD.org Cc: Subject: Re: threads/119920: fork broken in libpthread Date: Fri, 25 Jan 2008 05:50:28 -0500 Can you try this patch? I ported it from some mail regarding this issue on threads@ diff -ur lib/libpthread/thread/thr_kern.c lib/libpthread/thread/thr_kern.c --- lib/libpthread/thread/thr_kern.c 2006-03-16 23:29:07.000000000 +0000 +++ lib/libpthread/thread/thr_kern.c 2008-01-25 10:33:23.000000000 +0000 @@ -345,6 +345,17 @@ _LCK_SET_PRIVATE2(&curthread->kse->k_lockusers[i], NULL); } curthread->kse->k_locklevel = 0; + + /* + * Reinitialize the thread and signal locks so that + * sigaction() will work after a fork(). + */ + _lock_reinit(&curthread->lock, LCK_ADAPTIVE, _thr_lock_wait, + _thr_lock_wakeup); + _lock_reinit(&_thread_signal_lock, LCK_ADAPTIVE, _kse_lock_wait, + _kse_lock_wakeup); + + _thr_spinlock_init(); if (__isthreaded) { _thr_rtld_fini(); @@ -354,6 +365,20 @@ curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL; curthread->attr.flags |= PTHREAD_SCOPE_SYSTEM; + /* + * After a fork, it is possible that an upcall occurs in + * the parent KSE that fork()'d before the child process + * is fully created and before its vm space is copied. + * During the upcall, the tcb is set to null or to another + * thread, and this is what gets copied in the child process + * when the vm space is cloned sometime after the upcall + * occurs. Note that we shouldn't have to set the kcb, but + * we do it for completeness. + */ + _kcb_set(curthread->kse->k_kcb); + _tcb_set(curthread->kse->k_kcb, curthread->tcb); + + /* After a fork(), there child should have no pending signals. */ sigemptyset(&curthread->sigpend);