summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-10-22 02:55:37 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-10-22 02:55:37 +0000
commitc3055f140a4d8a272d10c1d92230c999faa87579 (patch)
tree08fab240c50610715c072563911289834aa09831 /sys
parent6c07a3d0cdbd3cf6c730c4dc4111504661189b9a (diff)
Adjust allocpid() to take into account lastpid
ok jsing@ kettensi@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_fork.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 4c0b932b92e..5e8fde114b4 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.190 2016/10/15 05:09:01 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.191 2016/10/22 02:55:36 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -568,7 +568,7 @@ ispidtaken(pid_t pid)
return (0);
}
-/* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */
+/* Find an unused pid */
pid_t
allocpid(void)
{
@@ -579,8 +579,10 @@ allocpid(void)
/* only used early on for system processes */
pid = ++lastpid;
} else {
+ /* Find an unused pid satisfying lastpid < pid <= PID_MAX */
do {
- pid = 1 + arc4random_uniform(PID_MAX);
+ pid = arc4random_uniform(PID_MAX - lastpid) + 1 +
+ lastpid;
} while (ispidtaken(pid));
}