diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2010-05-29 02:47:49 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2010-05-29 02:47:49 +0000 |
commit | 4cd43ec457223c517a5d0191d733907188f4960b (patch) | |
tree | 9ece2721a3dccbc7553c9553528a63c47be2b44c /sys/kern | |
parent | a1b8629a9b765083ee6780be822fed50910310f4 (diff) |
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')
-rw-r--r-- | sys/kern/kern_fork.c | 6 |
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) { |