Keep the process locked when calling ktrops() or ktrsetchildren() instead

of dropping the lock only to immediately reacquire it.
This commit is contained in:
John Baldwin 2010-08-17 21:34:19 +00:00
parent 187278cadc
commit fe41d17ab2

View File

@ -741,7 +741,6 @@ ktrace(td, uap)
PROC_UNLOCK(p); PROC_UNLOCK(p);
continue; continue;
} }
PROC_UNLOCK(p);
nfound++; nfound++;
if (descend) if (descend)
ret |= ktrsetchildren(td, p, ops, facs, vp); ret |= ktrsetchildren(td, p, ops, facs, vp);
@ -758,18 +757,13 @@ ktrace(td, uap)
* by pid * by pid
*/ */
p = pfind(uap->pid); p = pfind(uap->pid);
if (p == NULL) { if (p == NULL)
sx_sunlock(&proctree_lock);
error = ESRCH; error = ESRCH;
goto done; else
} error = p_cansee(td, p);
error = p_cansee(td, p);
/*
* The slock of the proctree lock will keep this process
* from going away, so unlocking the proc here is ok.
*/
PROC_UNLOCK(p);
if (error) { if (error) {
if (p != NULL)
PROC_UNLOCK(p);
sx_sunlock(&proctree_lock); sx_sunlock(&proctree_lock);
goto done; goto done;
} }
@ -841,11 +835,16 @@ ktrops(td, p, ops, facs, vp)
struct vnode *tracevp = NULL; struct vnode *tracevp = NULL;
struct ucred *tracecred = NULL; struct ucred *tracecred = NULL;
PROC_LOCK(p); PROC_LOCK_ASSERT(p, MA_OWNED);
if (!ktrcanset(td, p)) { if (!ktrcanset(td, p)) {
PROC_UNLOCK(p); PROC_UNLOCK(p);
return (0); return (0);
} }
if (p->p_flag & P_WEXIT) {
/* If the process is exiting, just ignore it. */
PROC_UNLOCK(p);
return (1);
}
mtx_lock(&ktrace_mtx); mtx_lock(&ktrace_mtx);
if (ops == KTROP_SET) { if (ops == KTROP_SET) {
if (p->p_tracevp != vp) { if (p->p_tracevp != vp) {
@ -900,6 +899,7 @@ ktrsetchildren(td, top, ops, facs, vp)
register int ret = 0; register int ret = 0;
p = top; p = top;
PROC_LOCK_ASSERT(p, MA_OWNED);
sx_assert(&proctree_lock, SX_LOCKED); sx_assert(&proctree_lock, SX_LOCKED);
for (;;) { for (;;) {
ret |= ktrops(td, p, ops, facs, vp); ret |= ktrops(td, p, ops, facs, vp);
@ -919,6 +919,7 @@ ktrsetchildren(td, top, ops, facs, vp)
} }
p = p->p_pptr; p = p->p_pptr;
} }
PROC_LOCK(p);
} }
/*NOTREACHED*/ /*NOTREACHED*/
} }