From owner-p4-projects@FreeBSD.ORG Thu Jan 29 14:25:33 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 81AF51065672; Thu, 29 Jan 2009 14:25:33 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4083B106566C for ; Thu, 29 Jan 2009 14:25:33 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 2CCFE8FC18 for ; Thu, 29 Jan 2009 14:25:33 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0TEPXBb081227 for ; Thu, 29 Jan 2009 14:25:33 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0TEPXrT081225 for perforce@freebsd.org; Thu, 29 Jan 2009 14:25:33 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Thu, 29 Jan 2009 14:25:33 GMT Message-Id: <200901291425.n0TEPXrT081225@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 156860 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jan 2009 14:25:34 -0000 http://perforce.freebsd.org/chv.cgi?CH=156860 Change 156860 by rwatson@rwatson_freebsd_capabilities on 2009/01/29 14:25:22 When close() is called on a process descriptor and the process isn't yet dead, we will kill it with SIGKILL--detach the process from its descriptor before reparenting to init since otherwise init won't be able to see it in wait4() and we end up with a zombie. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/sys/kern/sys_procdesc.c#10 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/sys/kern/sys_procdesc.c#10 (text+ko) ==== @@ -244,6 +244,12 @@ procdesc_free(struct procdesc *pd) { + /* + * When the last reference is released, we assert that the descriptor + * has been closed, but not that the process has exited, as we will + * detach the descriptor before the process dies if the descript is + * closed, as we can't wait synchronously. + */ if (refcount_release(&pd->pd_refcount)) { KASSERT(pd->pd_proc == NULL, ("procdesc_free: pd_proc != NULL")); @@ -351,9 +357,17 @@ /* * If the process is not yet dead, we need to kill it, but we * can't wait around synchronously for it to go away, as that - * path leads to madness (and deadlocks). Reparent the - * target to init(8) so that there's someone to pick up the - * pieces, then terminate with prejudice. + * path leads to madness (and deadlocks). First, detach the + * process from its descriptor so that its exit status will + * be reported normally. + */ + pd->pd_proc = NULL; + p->p_procdesc = NULL; + procdesc_free(pd); + + /* + * Next, reparent it to init(8) so that there's someone to + * pick up the pieces; finally, terminate with prejudice. */ p->p_sigparent = SIGCHLD; proc_reparent(p, initproc);