Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/filemon When following process parent pointers, lock...
details: https://anonhg.NetBSD.org/src/rev/1c305726fb7b
branches: trunk
changeset: 342796:1c305726fb7b
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sat Jan 09 07:27:31 2016 +0000
description:
When following process parent pointers, lock the new (parent) before
releasing the initial process.
diffstat:
sys/dev/filemon/filemon.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diffs (49 lines):
diff -r be6a8c93bfb4 -r 1c305726fb7b sys/dev/filemon/filemon.c
--- a/sys/dev/filemon/filemon.c Sat Jan 09 03:33:53 2016 +0000
+++ b/sys/dev/filemon/filemon.c Sat Jan 09 07:27:31 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: filemon.c,v 1.26 2016/01/08 08:57:14 pgoyette Exp $ */
+/* $NetBSD: filemon.c,v 1.27 2016/01/09 07:27:31 pgoyette Exp $ */
/*
* Copyright (c) 2010, Juniper Networks, Inc.
*
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.26 2016/01/08 08:57:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.27 2016/01/09 07:27:31 pgoyette Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -154,13 +154,14 @@
struct filemon *filemon;
struct proc * lp;
+ KASSERT(p != NULL);
if (!TAILQ_EMPTY(&filemons_inuse)) {
+ /*
+ * make sure p cannot exit
+ * until we have moved on to p_pptr
+ */
+ rw_enter(&p->p_reflock, RW_READER);
while (p) {
- /*
- * make sure p cannot exit
- * until we have moved on to p_pptr
- */
- rw_enter(&p->p_reflock, RW_READER);
TAILQ_FOREACH(filemon, &filemons_inuse, fm_link) {
if (p->p_pid == filemon->fm_pid) {
rw_exit(&p->p_reflock);
@@ -169,6 +170,10 @@
}
lp = p;
p = p->p_pptr;
+
+ /* lock parent before releasing child */
+ if (p != NULL)
+ rw_enter(&p->p_reflock, RW_READER);
rw_exit(&lp->p_reflock);
}
}
Home |
Main Index |
Thread Index |
Old Index