summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@sun.com>2009-05-19 01:14:11 -0700
committerAlan Coopersmith <alan.coopersmith@sun.com>2009-05-19 01:14:11 -0700
commit346a316f5e39ca6d99b98372914294988e79758d (patch)
tree26f1b53531fa3a516190d83d03ddb7083aa3f3f1
parenta1583d53a44f65d0930282e193365f5605bde547 (diff)
Simplify OPEN_MAX #ifdefs down to POSIX standard sysconf(_SC_OPEN_MAX)
Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
-rw-r--r--os/access.c11
-rw-r--r--os/connection.c13
-rw-r--r--os/osdep.h52
-rw-r--r--os/osglue.c15
4 files changed, 21 insertions, 70 deletions
diff --git a/os/access.c b/os/access.c
index 7a60907..0b2ae8a 100644
--- a/os/access.c
+++ b/os/access.c
@@ -60,13 +60,18 @@ long MaxClients = DEFAULT_CLIENT_LIMIT;
void
AccessSetConnectionLimit(int num)
{
- num++; /* take serverClient into account */
- if (num > MAXSOCKS) {
+ int newlim = num + 8; /* allow room for serverClient, logs, etc. */
+ int maxfd = sysconf(_SC_OPEN_MAX) - 1;
+
+ if ((maxfd < 0) || (maxfd > MAXSOCKS)) {
+ maxfd = MAXSOCKS;
+ }
+ if (newlim > maxfd) {
ErrorF("Client limit of %d too high; using default of %d\n",
num, DEFAULT_CLIENT_LIMIT);
return;
}
- MaxClients = num;
+ MaxClients = newlim;
}
/* ARGSUSED */
diff --git a/os/connection.c b/os/connection.c
index 8510be0..5194acc 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -177,20 +177,9 @@ CreateSockets(int old_listen_count, OldListenRec *old_listen)
for (i = 0; i < MAXSOCKS; i++)
ConnectionTranslation[i] = 0;
-#ifdef XNO_SYSCONF /* should only be on FreeBSD 1.x and NetBSD 0.x */
-#undef _SC_OPEN_MAX
-#endif
-#ifdef _SC_OPEN_MAX
lastfdesc = sysconf(_SC_OPEN_MAX) - 1;
-#else
-#if defined(hpux) || defined(__UNIXOS2__)
- lastfdesc = _NFILE - 1;
-#else
- lastfdesc = getdtablesize() - 1;
-#endif /* hpux */
-#endif
- if (lastfdesc > MAXSOCKS) {
+ if ((lastfdesc < 0) || (lastfdesc > MAXSOCKS)) {
lastfdesc = MAXSOCKS;
}
diff --git a/os/osdep.h b/os/osdep.h
index 74297cc..ace43ea 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -55,18 +55,16 @@ in this Software without prior written authorization from The Open Group.
#define BUFWATERMARK 8192
#define MAXBUFSIZE (1 << 15)
-#ifndef sgi /* SGI defines OPEN_MAX in a useless way */
-# ifdef _POSIX_SOURCE
-# include <limits.h>
-# else
-# define _POSIX_SOURCE
-# include <limits.h>
-# undef _POSIX_SOURCE
-# endif
+#ifdef _POSIX_SOURCE
+# include <limits.h>
+#else
+# define _POSIX_SOURCE
+# include <limits.h>
+# undef _POSIX_SOURCE
#endif
+#include <sys/param.h>
#ifndef PATH_MAX
-# include <sys/param.h>
# ifndef PATH_MAX
# ifdef MAXPATHLEN
# define PATH_MAX MAXPATHLEN
@@ -76,41 +74,7 @@ in this Software without prior written authorization from The Open Group.
# endif
#endif /* PATH_MAX */
-#ifndef OPEN_MAX
-#if defined(__UNIXOS2__) || defined(__QNX__)
-#define OPEN_MAX 256
-#else
-#ifdef SVR4
-#define OPEN_MAX 128
-#else
-#include <sys/param.h>
-#ifdef __GNU__
-#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
-#endif /*__GNU__*/
-#ifndef OPEN_MAX
-#ifdef SCO325
-#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
-#else
-#if defined(NOFILE) && !defined(NOFILES_MAX)
-#define OPEN_MAX NOFILE
-#else
-#define OPEN_MAX NOFILES_MAX
-#endif
-#endif
-#endif
-#endif
-#endif
-#endif
-
-#if defined(__GNU__) || defined(SCO325)
-#define MAXSOCKS 128
-#else /*__GNU__*/
-#if OPEN_MAX <= 128 /* 128 is value of MAXCLIENTS */
-#define MAXSOCKS (OPEN_MAX - 1)
-#else
-#define MAXSOCKS 128
-#endif
-#endif /*__GNU__*/
+#define MAXSOCKS MAXCLIENTS
#include <stddef.h>
diff --git a/os/osglue.c b/os/osglue.c
index 5549d26..b99b042 100644
--- a/os/osglue.c
+++ b/os/osglue.c
@@ -63,6 +63,7 @@ in this Software without prior written authorization from The Open Group.
#define _NFILE 256
#endif
#include "globals.h"
+#include "osdep.h"
Bool drone_server = FALSE;
@@ -294,18 +295,10 @@ CloneMyself(void)
old_listen_arg[0] = '\0';
-#ifdef XNO_SYSCONF /* should only be on FreeBSD 1.x and NetBSD 0.x */
-#undef _SC_OPEN_MAX
-#endif
-#ifdef _SC_OPEN_MAX
lastfdesc = sysconf(_SC_OPEN_MAX) - 1;
-#else
-#if defined(hpux) || defined(__UNIXOS2__)
- lastfdesc = _NFILE - 1;
-#else
- lastfdesc = getdtablesize() - 1;
-#endif /* hpux */
-#endif
+ if ( (lastfdesc < 0) || (lastfdesc > MAXSOCKS)) {
+ lastfdesc = MAXSOCKS;
+ }
NoticeF("attempting clone...\n");
chdir("/");