summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_fork.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2010-05-29 02:47:48 +0000
committerguenther <guenther@openbsd.org>2010-05-29 02:47:48 +0000
commit598bddab0a66c556d74b048f17c52bd1aacbc928 (patch)
tree07f57cb36df2889b95677499ef6a7e1f82a937bd /sys/kern/kern_fork.c
parent${PARAM} is now included in ${CPPFLAGS}, so stop passing it separately (diff)
downloadwireguard-openbsd-598bddab0a66c556d74b048f17c52bd1aacbc928.tar.xz
wireguard-openbsd-598bddab0a66c556d74b048f17c52bd1aacbc928.zip
As noted by art, two processes with the same pid would be bad. Grab
the allproclk before searching for a free pid so that we don't sleep between picking one and adding it to the list that is searched. Also, keep holding the lock until after the PIDHASH update. ok art@, tedu@
Diffstat (limited to 'sys/kern/kern_fork.c')
-rw-r--r--sys/kern/kern_fork.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 770174abe05..b67e1e0af96 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.110 2010/05/18 22:26:10 tedu Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.111 2010/05/29 02:47:48 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -409,15 +409,15 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
#endif
/* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */
+ rw_enter_write(&allproclk);
do {
lastpid = 1 + (randompid ? arc4random() : lastpid) % PID_MAX;
} while (pidtaken(lastpid));
p2->p_pid = lastpid;
- rw_enter_write(&allproclk);
LIST_INSERT_HEAD(&allproc, p2, p_list);
- rw_exit_write(&allproclk);
LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
+ rw_exit_write(&allproclk);
LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
LIST_INSERT_AFTER(p1, p2, p_pglist);
if (p2->p_flag & P_TRACED) {