From owner-freebsd-current@FreeBSD.ORG Wed Feb 15 18:24:08 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C2C411065673 for ; Wed, 15 Feb 2012 18:24:08 +0000 (UTC) (envelope-from dmitrym@juniper.net) Received: from exprod7og111.obsmtp.com (exprod7og111.obsmtp.com [64.18.2.175]) by mx1.freebsd.org (Postfix) with ESMTP id 56DB18FC17 for ; Wed, 15 Feb 2012 18:24:08 +0000 (UTC) Received: from P-EMHUB01-HQ.jnpr.net ([66.129.224.36]) (using TLSv1) by exprod7ob111.postini.com ([64.18.6.12]) with SMTP ID DSNKTzv4RnLkRmJQE2Z64lpS4sXVpBiuOxZV@postini.com; Wed, 15 Feb 2012 10:24:08 PST Received: from magenta.juniper.net (172.17.27.123) by P-EMHUB01-HQ.jnpr.net (172.24.192.33) with Microsoft SMTP Server (TLS) id 8.3.213.0; Wed, 15 Feb 2012 10:22:18 -0800 Received: from [172.24.26.191] (dmitrym-lnx.jnpr.net [172.24.26.191]) by magenta.juniper.net (8.11.3/8.11.3) with ESMTP id q1FIMI176289; Wed, 15 Feb 2012 10:22:18 -0800 (PST) (envelope-from dmitrym@juniper.net) Message-ID: <4F3BF7D5.7010609@juniper.net> Date: Wed, 15 Feb 2012 10:22:13 -0800 From: Dmitry Mikulin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 MIME-Version: 1.0 To: Konstantin Belousov References: <20120210001725.GJ3283@deviant.kiev.zoral.com.ua> <4F3478B3.9040809@juniper.net> <20120213152825.GH3283@deviant.kiev.zoral.com.ua> <4F3988E8.2040705@juniper.net> <20120213222521.GK3283@deviant.kiev.zoral.com.ua> <4F3993C5.5020703@juniper.net> <20120215163252.GZ3283@deviant.kiev.zoral.com.ua> <4F3BE9C2.8040908@juniper.net> <20120215174031.GB3283@deviant.kiev.zoral.com.ua> <4F3BF164.2020506@juniper.net> <20120215180210.GC3283@deviant.kiev.zoral.com.ua> In-Reply-To: <20120215180210.GC3283@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: f8e27f27-03b2-4c3e-9447-119194e72cb6 X-Mailman-Approved-At: Wed, 15 Feb 2012 18:37:11 +0000 Cc: freebsd-current Current , Marcel Moolenaar Subject: Re: [ptrace] please review follow fork/exec changes X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Feb 2012 18:24:08 -0000 I'm not sure we are on the same page. Let's do it from the very beginning. The real parent calls wait4() and enters kern_wait() while the child is in a zombie state. The child is in the gdb's children list and the real parent's orphan list. We enter proc_reap() because the child is caught by the orphan list of the real parent. We are at if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) { doing proc_reparent() to the real parent of the child. The child is in the real parent's orphan list and will be removed from it by proc_reparent and added to the orphan list of gdb. After we're done re-parenting, the child is in the children list of the real parent and in the orphan list of gdb. On the way out of proc_reap we clear p->p_oppid and wait4() returns the exit code to the real parent. The child is not yet destroyed and is being waited for by gdb since it's on gdb's orphan list. We enter proc_reap() through gdb's wait4() and kern_wait(). We don't enter the following this time if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) { and go to the actual destruction of the process.