svn commit: r211439 - head/sys/kern
John Baldwin
jhb at FreeBSD.org
Tue Aug 17 21:34:19 UTC 2010
Author: jhb
Date: Tue Aug 17 21:34:19 2010
New Revision: 211439
URL: http://svn.freebsd.org/changeset/base/211439
Log:
Keep the process locked when calling ktrops() or ktrsetchildren() instead
of dropping the lock only to immediately reacquire it.
Modified:
head/sys/kern/kern_ktrace.c
Modified: head/sys/kern/kern_ktrace.c
==============================================================================
--- head/sys/kern/kern_ktrace.c Tue Aug 17 21:28:40 2010 (r211438)
+++ head/sys/kern/kern_ktrace.c Tue Aug 17 21:34:19 2010 (r211439)
@@ -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*/
}
More information about the svn-src-all
mailing list