From 015cd8dc93db4dd76ee834ff12f692e7a6bbf6e9 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sat, 17 Feb 2018 00:24:50 +0000 Subject: [PATCH] On process exit signal the parent after dropping the proctree lock. --- sys/kern/kern_exit.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index d19e19a7584..91375e43570 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -193,6 +193,7 @@ exit1(struct thread *td, int rval, int signo) struct proc *p, *nq, *q, *t; struct thread *tdt; ksiginfo_t *ksi, *ksi1; + int signal_parent; mtx_assert(&Giant, MA_NOTOWNED); KASSERT(rval == 0 || signo == 0, ("exit1 rv %d sig %d", rval, signo)); @@ -559,6 +560,7 @@ exit1(struct thread *td, int rval, int signo) * procdesc_exit() to serialize concurrent calls to close() and * exit(). */ + signal_parent = 0; if (p->p_procdesc == NULL || procdesc_exit(p)) { /* * Notify parent that we're gone. If parent has the @@ -588,18 +590,25 @@ exit1(struct thread *td, int rval, int signo) } else mtx_unlock(&p->p_pptr->p_sigacts->ps_mtx); - if (p->p_pptr == p->p_reaper || p->p_pptr == initproc) - childproc_exited(p); - else if (p->p_sigparent != 0) { - if (p->p_sigparent == SIGCHLD) - childproc_exited(p); - else /* LINUX thread */ - kern_psignal(p->p_pptr, p->p_sigparent); + if (p->p_pptr == p->p_reaper || p->p_pptr == initproc) { + signal_parent = 1; + } else if (p->p_sigparent != 0) { + if (p->p_sigparent == SIGCHLD) { + signal_parent = 1; + } else { /* LINUX thread */ + signal_parent = 2; + } } } else PROC_LOCK(p->p_pptr); sx_xunlock(&proctree_lock); + if (signal_parent == 1) { + childproc_exited(p); + } else if (signal_parent == 2) { + kern_psignal(p->p_pptr, p->p_sigparent); + } + /* Tell the prison that we are gone. */ prison_proc_free(p->p_ucred->cr_prison);