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.
This commit is contained in:
John Dyson 1996-03-03 19:48:45 +00:00
parent 4f735d8edb
commit ef5dc8a96d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=14362

View File

@ -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 @@ fork1(p1, forktype, rforkflags, retval)
* 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 */