From owner-svn-src-all@FreeBSD.ORG Sun Aug 24 09:02:17 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B6879F3D; Sun, 24 Aug 2014 09:02:17 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 883AD37E8; Sun, 24 Aug 2014 09:02:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7O92G5U083386; Sun, 24 Aug 2014 09:02:16 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7O92GsJ083385; Sun, 24 Aug 2014 09:02:16 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201408240902.s7O92GsJ083385@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 24 Aug 2014 09:02:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r270443 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Aug 2014 09:02:17 -0000 Author: mjg Date: Sun Aug 24 09:02:16 2014 New Revision: 270443 URL: http://svnweb.freebsd.org/changeset/base/270443 Log: Properly reparent traced processes when the tracer dies. Previously they were uncoditionally reparented to init. In effect it was possible that tracee was never returned to original parent. Reviewed by: kib MFC after: 1 week Modified: head/sys/kern/kern_exit.c Modified: head/sys/kern/kern_exit.c ============================================================================== --- head/sys/kern/kern_exit.c Sun Aug 24 08:03:59 2014 (r270442) +++ head/sys/kern/kern_exit.c Sun Aug 24 09:02:16 2014 (r270443) @@ -156,7 +156,8 @@ sys_sys_exit(struct thread *td, struct s void exit1(struct thread *td, int rv) { - struct proc *p, *nq, *q; + struct proc *p, *nq, *q, *t; + struct thread *tdt; struct vnode *ttyvp = NULL; mtx_assert(&Giant, MA_NOTOWNED); @@ -437,7 +438,9 @@ exit1(struct thread *td, int rv) WITNESS_WARN(WARN_PANIC, NULL, "process (pid %d) exiting", p->p_pid); /* - * Reparent all of our children to init. + * Reparent all children processes: + * - traced ones to the original parent (or init if we are that parent) + * - the rest to init */ sx_xlock(&proctree_lock); q = LIST_FIRST(&p->p_children); @@ -446,15 +449,23 @@ exit1(struct thread *td, int rv) for (; q != NULL; q = nq) { nq = LIST_NEXT(q, p_sibling); PROC_LOCK(q); - proc_reparent(q, initproc); q->p_sigparent = SIGCHLD; - /* - * Traced processes are killed - * since their existence means someone is screwing up. - */ - if (q->p_flag & P_TRACED) { - struct thread *temp; + if (!(q->p_flag & P_TRACED)) { + proc_reparent(q, initproc); + } else { + /* + * Traced processes are killed since their existence + * means someone is screwing up. + */ + t = proc_realparent(q); + if (t == p) { + proc_reparent(q, initproc); + } else { + PROC_LOCK(t); + proc_reparent(q, t); + PROC_UNLOCK(t); + } /* * Since q was found on our children list, the * proc_reparent() call moved q to the orphan @@ -463,8 +474,8 @@ exit1(struct thread *td, int rv) */ clear_orphan(q); q->p_flag &= ~(P_TRACED | P_STOPPED_TRACE); - FOREACH_THREAD_IN_PROC(q, temp) - temp->td_dbgflags &= ~TDB_SUSPEND; + FOREACH_THREAD_IN_PROC(q, tdt) + tdt->td_dbgflags &= ~TDB_SUSPEND; kern_psignal(q, SIGKILL); } PROC_UNLOCK(q);