From ef5dc8a96dc4d736be7d38b86a31dbec0fd49b1f Mon Sep 17 00:00:00 2001 From: John Dyson Date: Sun, 3 Mar 1996 19:48:45 +0000 Subject: [PATCH] Keep fork from over extending the number of processes. Since u_map is sized exactly for maxproc, the occasional overrunning the maxproc limit can cause problems. --- sys/kern/kern_fork.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index dbb56c454484..743128cacb67 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94 - * $Id: kern_fork.c,v 1.16 1996/01/03 21:42:02 wollman Exp $ + * $Id: kern_fork.c,v 1.17 1996/02/23 18:49:17 peter Exp $ */ #include "opt_ktrace.h" @@ -148,6 +148,12 @@ fork1(p1, forktype, rforkflags, retval) tablefull("proc"); return (EAGAIN); } + /* + * Increment the nprocs resource before blocking can occur. There + * are hard-limits as to the number of processes that can run. + */ + nprocs++; + /* * Increment the count of procs running with this uid. Don't allow * a nonprivileged user to exceed their current limit. @@ -155,6 +161,10 @@ fork1(p1, forktype, rforkflags, retval) count = chgproccnt(uid, 1); if (uid != 0 && count > p1->p_rlimit[RLIMIT_NPROC].rlim_cur) { (void)chgproccnt(uid, -1); + /* + * Back out the process count + */ + nprocs--; return (EAGAIN); } @@ -214,7 +224,6 @@ again: * rearranging code. Yes, it *is* terribly ugly, but at least * it works. */ - nprocs++; p2 = newproc; #define Vp2 ((volatile struct proc *)p2) Vp2->p_stat = SIDL; /* protect against others */