diff options
author | 2002-10-31 01:33:27 +0000 | |
---|---|---|
committer | 2002-10-31 01:33:27 +0000 | |
commit | 278c44d1388c299f284136279e9e28c678d2bbd4 (patch) | |
tree | 8629e39f50dec294c281d0c5412303543ae379ea /sys/kern/kern_fork.c | |
parent | Introduce some better feedback during attempted ftp installations. In (diff) | |
download | wireguard-openbsd-278c44d1388c299f284136279e9e28c678d2bbd4.tar.xz wireguard-openbsd-278c44d1388c299f284136279e9e28c678d2bbd4.zip |
Defer pid allocation and making the new process visible until after it's
been fully initialized. Otherwise the scheduler and other things can
accidentally stumble into semi-initialized processes and strange things
can happen. This also requires us to do systrace attachment a bit later.
Debugging help from fgs@
Diffstat (limited to 'sys/kern/kern_fork.c')
-rw-r--r-- | sys/kern/kern_fork.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index b502c8443de..3e014739b1f 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.58 2002/10/22 01:48:25 art Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.59 2002/10/31 01:33:27 art Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -133,7 +133,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, { struct proc *p2; uid_t uid; - struct proc *newproc; struct vmspace *vm; int count; vaddr_t uaddr; @@ -180,20 +179,11 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, */ /* Allocate new proc. */ - newproc = pool_get(&proc_pool, PR_WAITOK); + p2 = pool_get(&proc_pool, PR_WAITOK); - /* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */ - do { - lastpid = 1 + (randompid ? arc4random() : lastpid) % PID_MAX; - } while (pidtaken(lastpid)); - - p2 = newproc; p2->p_stat = SIDL; /* protect against others */ - p2->p_pid = lastpid; p2->p_exitsig = exitsig; - LIST_INSERT_HEAD(&allproc, p2, p_list); - p2->p_forw = p2->p_back = NULL; /* shouldn't be necessary */ - LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash); + p2->p_forw = p2->p_back = NULL; /* * Make a proc table entry for the new process. @@ -273,10 +263,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, VREF(p2->p_tracep); } #endif -#if NSYSTRACE > 0 - if (ISSET(p1->p_flag, P_SYSTRACE)) - systrace_fork(p1, p2); -#endif /* * set priority of child to be that of parent @@ -341,6 +327,20 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, forkstat.sizkthread += vm->vm_dsize + vm->vm_ssize; } + /* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */ + do { + lastpid = 1 + (randompid ? arc4random() : lastpid) % PID_MAX; + } while (pidtaken(lastpid)); + p2->p_pid = lastpid; + + LIST_INSERT_HEAD(&allproc, p2, p_list); + LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash); + +#if NSYSTRACE > 0 + if (ISSET(p1->p_flag, P_SYSTRACE)) + systrace_fork(p1, p2); +#endif + /* * Make child runnable, set start time, and add to run queue. */ |