diff options
| author | 2016-10-22 02:55:36 +0000 | |
|---|---|---|
| committer | 2016-10-22 02:55:36 +0000 | |
| commit | 424d010a7e18598a43c74e4023ac4b86af51df65 (patch) | |
| tree | d92b6d84726ccd16d62fabbdb2fbb2e4327657a5 /sys/kern/kern_fork.c | |
| parent | Delete dead copy of pr->ps_vmspace; uvmspace_exec() can change it anyway (diff) | |
| download | wireguard-openbsd-424d010a7e18598a43c74e4023ac4b86af51df65.tar.xz wireguard-openbsd-424d010a7e18598a43c74e4023ac4b86af51df65.zip | |
Adjust allocpid() to take into account lastpid
ok jsing@ kettensi@
Diffstat (limited to 'sys/kern/kern_fork.c')
| -rw-r--r-- | sys/kern/kern_fork.c | 8 |
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)); } |
