From 3c319633569e3d5212b1b525fd5216a542996a9e Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 15 Aug 2012 17:49:47 -0700 Subject: [PATCH] Kernel - Fix numerous procfs/ptrace issues (2) * The last fix wasn't quite right. Fix it for real. --- sys/kern/kern_proc.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index bda5911fb8..728b9c5e5c 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -177,15 +177,20 @@ pstall(struct proc *p, const char *wmesg, int count) tsleep_interlock(&p->p_lock, 0); /* - * If someone is trying to single-step the process they can - * prevent us from going into zombie-land. + * If someone is trying to single-step the process during + * an exec or an exit they can deadlock us because procfs + * sleeps with the process held. */ - if (p->p_step) { - spin_lock(&p->p_spin); - p->p_stops = 0; - p->p_step = 0; - spin_unlock(&p->p_spin); - wakeup(&p->p_step); + if (p->p_stops) { + if (p->p_flags & P_INEXEC) { + wakeup(&p->p_stype); + } else if (p->p_flags & P_POSTEXIT) { + spin_lock(&p->p_spin); + p->p_stops = 0; + p->p_step = 0; + spin_unlock(&p->p_spin); + wakeup(&p->p_stype); + } } if (atomic_cmpset_int(&p->p_lock, o, n)) { -- 2.41.0