From: millert Date: Thu, 27 Mar 1997 05:35:25 +0000 (+0000) Subject: Implement NOFILE_MAX--hard limit on max descriptors per proccess. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=aa66f5ec26edcacab151685c6c4b373569c33a0e;p=openbsd Implement NOFILE_MAX--hard limit on max descriptors per proccess. Future direction, might make sense to make this a kernel symbol tha is sysctl-able. --- diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 496426a6070..eb4e1712fe1 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.20 1996/11/06 01:29:46 deraadt Exp $ */ +/* $OpenBSD: init_main.c,v 1.21 1997/03/27 05:35:28 millert Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,10 @@ extern void nfs_init __P((void)); #endif +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + char copyright[] = "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\n\n"; @@ -239,6 +244,8 @@ main(framep) limit0.pl_rlimit[i].rlim_cur = limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY; limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE; + limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX, + (maxfiles - NOFILE > NOFILE) ? maxfiles - NOFILE : NOFILE); limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC; i = ptoa(cnt.v_free_count); limit0.pl_rlimit[RLIMIT_RSS].rlim_max = i; diff --git a/sys/sys/param.h b/sys/sys/param.h index 4cb4f8bc2ac..cd1490f63e8 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.11 1996/10/25 11:14:45 deraadt Exp $ */ +/* $OpenBSD: param.h,v 1.12 1997/03/27 05:35:25 millert Exp $ */ /* $NetBSD: param.h,v 1.23 1996/03/17 01:02:29 thorpej Exp $ */ /*- @@ -71,7 +71,8 @@ #define MAXUPRC CHILD_MAX /* max simultaneous processes */ #define NCARGS ARG_MAX /* max bytes for an exec function */ #define NGROUPS NGROUPS_MAX /* max number groups */ -#define NOFILE OPEN_MAX /* max open files per process */ +#define NOFILE OPEN_MAX /* max open files per process (soft) */ +#define NOFILE_MAX 1024 /* max open files per process (hard) */ #define NOGROUP 65535 /* marker for empty group set member */ #define MAXHOSTNAMELEN 256 /* max hostname size */