summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1997-06-05 10:15:22 +0000
committerderaadt <deraadt@openbsd.org>1997-06-05 10:15:22 +0000
commitdd13bf2f878d513fc8d54202e8e4715ead76ca25 (patch)
tree731a9e44e855f5e5af8e9dfceba3bdf10a7ba004
parentgetpid() is going to be OK in a few minutes (diff)
downloadwireguard-openbsd-dd13bf2f878d513fc8d54202e8e4715ead76ca25.tar.xz
wireguard-openbsd-dd13bf2f878d513fc8d54202e8e4715ead76ca25.zip
random pid generation, heh
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/kern_fork.c12
-rw-r--r--sys/sys/proc.h3
3 files changed, 10 insertions, 8 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 69d63bcba56..27ac4fec18b 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.22 1997/04/19 18:40:02 pefo Exp $ */
+/* $OpenBSD: init_main.c,v 1.23 1997/06/05 10:15:24 deraadt Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -407,6 +407,7 @@ main(framep)
microtime(&rtv);
srandom((u_long)(rtv.tv_sec ^ rtv.tv_usec));
+ randompid = 1;
/* The scheduler is an infinite loop. */
scheduler();
/* NOTREACHED */
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index a89382a82ab..9871a9fc0bd 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.7 1997/02/18 00:11:47 deraadt Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.8 1997/06/05 10:15:26 deraadt Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -54,12 +54,14 @@
#include <sys/file.h>
#include <sys/acct.h>
#include <sys/ktrace.h>
+#include <dev/rndvar.h>
#include <sys/syscallargs.h>
#include <vm/vm.h>
int nprocs = 1; /* process 0 */
+int randompid; /* when set to 1, pid's go random */
pid_t lastpid;
#define ISFORK 0
@@ -155,11 +157,9 @@ fork1(p1, forktype, rforkflags, retval)
/* Allocate new proc. */
MALLOC(newproc, struct proc *, sizeof(struct proc), M_PROC, M_WAITOK);
- /*
- * Find an unused process ID. We remember a range of unused IDs
- * ready to use (from lastpid+1 through pidchecked-1).
- */
lastpid++;
+ if (randompid)
+ lastpid = PID_MAX;
retry:
/*
* If the process ID prototype has wrapped around,
@@ -167,7 +167,7 @@ retry:
* tend to include daemons that don't exit.
*/
if (lastpid >= PID_MAX) {
- lastpid = 100;
+ lastpid = arc4random() % PID_MAX;
pidchecked = 0;
}
if (lastpid >= pidchecked) {
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 0685ae7c9b8..f80c160bf41 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.13 1997/02/01 21:49:30 deraadt Exp $ */
+/* $OpenBSD: proc.h,v 1.14 1997/06/05 10:15:22 deraadt Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -283,6 +283,7 @@ extern u_long pgrphash;
extern struct proc *curproc; /* Current running proc. */
extern struct proc proc0; /* Process slot for swapper. */
extern int nprocs, maxproc; /* Current and max number of procs. */
+extern int randompid; /* fork() should create random pid's */
LIST_HEAD(proclist, proc);
extern struct proclist allproc; /* List of all processes. */