diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2007-03-06 01:59:44 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2007-03-06 01:59:44 +0000 |
commit | d94b0404a8671d15c6c4b121ec382e44ccbe0680 (patch) | |
tree | fddaf414f65fc63ef92cd1d54e854b38d482001f /libexec/spamd | |
parent | 37c07d65ff47c5ffaa3c9d9a52c8d7ff4c038b98 (diff) |
Make the maximum number of connections dependant on kern.maxfiles rather
than a hardcoded value.
ok reyk@, deraadt@ with knfisms and saner variable names
Diffstat (limited to 'libexec/spamd')
-rw-r--r-- | libexec/spamd/spamd.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c index 16a339a276e..1457b8a0f45 100644 --- a/libexec/spamd/spamd.c +++ b/libexec/spamd/spamd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spamd.c,v 1.95 2007/03/05 21:25:29 beck Exp $ */ +/* $OpenBSD: spamd.c,v 1.96 2007/03/06 01:59:43 beck Exp $ */ /* * Copyright (c) 2002 Theo de Raadt. All rights reserved. @@ -28,6 +28,7 @@ #include <sys/file.h> #include <sys/wait.h> #include <sys/socket.h> +#include <sys/sysctl.h> #include <sys/resource.h> #include <netinet/in.h> @@ -127,6 +128,7 @@ size_t cbs, cbu; time_t t; #define MAXCON 800 +int maxfiles; int maxcon = MAXCON; int maxblack = MAXCON; int blackcount; @@ -961,6 +963,24 @@ handled: } } +static int +get_maxfiles(void) +{ + int mib[2], maxfiles; + size_t len; + + mib[0] = CTL_KERN; + mib[1] = KERN_MAXFILES; + len = sizeof(maxfiles); + if (sysctl(mib, 2, &maxfiles, &len, NULL, 0) == -1) + return(MAXCON); + if ((maxfiles - 200) < 10) + errx(1, "kern.maxfiles is only %d, can not continue\n", + maxfiles); + else + return(maxfiles - 200); +} + int main(int argc, char *argv[]) { @@ -992,7 +1012,11 @@ main(int argc, char *argv[]) if (gethostname(hostname, sizeof hostname) == -1) err(1, "gethostname"); - + maxfiles = get_maxfiles(); + if (maxcon > maxfiles) + maxcon = maxfiles; + if (maxblack > maxfiles) + maxblack = maxfiles; while ((ch = getopt(argc, argv, "45l:c:B:p:bdG:h:r:s:S:n:vw:y:Y:")) != -1) { switch (ch) { @@ -1011,8 +1035,12 @@ main(int argc, char *argv[]) break; case 'c': i = atoi(optarg); - if (i > MAXCON) + if (i > maxfiles) { + fprintf(stderr, + "%d > system max of %d connections\n", + i, maxfiles); usage(); + } maxcon = i; break; case 'p': |