summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_ktrace.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2010-08-17 21:34:19 +0000
committerjhb <jhb@FreeBSD.org>2010-08-17 21:34:19 +0000
commitd64a4df9413ce087d363d0c3deb9a781e3ea4685 (patch)
tree63d6e5914e08b47a7e7467a5217a4447f4e0e72d /sys/kern/kern_ktrace.c
parentf63ab9228e0818135be1431b017306e2062147ae (diff)
downloadFreeBSD-src-d64a4df9413ce087d363d0c3deb9a781e3ea4685.zip
FreeBSD-src-d64a4df9413ce087d363d0c3deb9a781e3ea4685.tar.gz
Keep the process locked when calling ktrops() or ktrsetchildren() instead
of dropping the lock only to immediately reacquire it.
Diffstat (limited to 'sys/kern/kern_ktrace.c')
-rw-r--r--sys/kern/kern_ktrace.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index d5eb4e1..2658437 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -741,7 +741,6 @@ ktrace(td, uap)
PROC_UNLOCK(p);
continue;
}
- PROC_UNLOCK(p);
nfound++;
if (descend)
ret |= ktrsetchildren(td, p, ops, facs, vp);
@@ -758,18 +757,13 @@ ktrace(td, uap)
* by pid
*/
p = pfind(uap->pid);
- if (p == NULL) {
- sx_sunlock(&proctree_lock);
+ if (p == NULL)
error = ESRCH;
- goto done;
- }
- 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);
+ else
+ error = p_cansee(td, p);
if (error) {
+ if (p != NULL)
+ PROC_UNLOCK(p);
sx_sunlock(&proctree_lock);
goto done;
}
@@ -841,11 +835,16 @@ ktrops(td, p, ops, facs, vp)
struct vnode *tracevp = NULL;
struct ucred *tracecred = NULL;
- PROC_LOCK(p);
+ PROC_LOCK_ASSERT(p, MA_OWNED);
if (!ktrcanset(td, p)) {
PROC_UNLOCK(p);
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);
if (ops == KTROP_SET) {
if (p->p_tracevp != vp) {
@@ -900,6 +899,7 @@ ktrsetchildren(td, top, ops, facs, vp)
register int ret = 0;
p = top;
+ PROC_LOCK_ASSERT(p, MA_OWNED);
sx_assert(&proctree_lock, SX_LOCKED);
for (;;) {
ret |= ktrops(td, p, ops, facs, vp);
@@ -919,6 +919,7 @@ ktrsetchildren(td, top, ops, facs, vp)
}
p = p->p_pptr;
}
+ PROC_LOCK(p);
}
/*NOTREACHED*/
}
OpenPOWER on IntegriCloud