rsroka / rpms / rsyslog

Forked from rpms/rsyslog 6 years ago
Clone
Blob Blame History Raw
diff -up rsyslog-3.22.1/configure.ac.orig rsyslog-3.22.1/configure.ac
--- rsyslog-3.22.1/configure.ac.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/configure.ac	2009-11-23 15:03:00.000000000 +0100
@@ -315,6 +315,22 @@ AC_ARG_ENABLE([fsstnd],
     AC_DEFINE([FSSTND], [1], [Description])
   ])
 
+
+# support for unlimited select() syscall
+AC_ARG_ENABLE(unlimited_select,
+        [AS_HELP_STRING([--enable-unlimited-select],[Enable unlimited select() syscall @<:@default=no@:>@])],
+        [case "${enableval}" in
+         yes) enable_unlimited_select="yes" ;;
+          no) enable_unlimited_select="no" ;;
+           *) AC_MSG_ERROR(bad value ${enableval} for --enable-unlimited-select) ;;
+         esac],
+        [enable_unlimited_select="no"]
+)
+if test "$enable_unlimited_select" = "yes"; then
+        AC_DEFINE(USE_UNLIMITED_SELECT, 1, [If defined, the select() syscall won't be limited to a particular number of file descriptors.])
+fi
+
+
 # debug
 AC_ARG_ENABLE(debug,
         [AS_HELP_STRING([--enable-debug],[Enable debug mode @<:@default=no@:>@])],
@@ -707,6 +723,7 @@ echo "Large file support enabled:       
 echo "Networking support enabled:               $enable_inet"
 echo "GnuTLS network stream driver enabled:     $enable_gnutls"
 echo "Enable GSSAPI Kerberos 5 support:         $want_gssapi_krb5"
+echo "Unlimited select() support enabled:       $enable_unlimited_select"
 echo "Debug mode enabled:                       $enable_debug"
 echo "Runtime Instrumentation enabled:          $enable_rtinst"
 echo "Diagnostic tools enabled:                 $enable_diagtools"
diff -up rsyslog-3.22.1/gss-misc.c.orig rsyslog-3.22.1/gss-misc.c
--- rsyslog-3.22.1/gss-misc.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/gss-misc.c	2009-11-23 15:03:00.000000000 +0100
@@ -51,11 +51,14 @@
 #include "obj.h"
 #include "errmsg.h"
 #include "gss-misc.h"
+#include "glbl.h"
+#include "unlimited_select.h"
 
 MODULE_TYPE_LIB
 
 /* static data */
 DEFobjStaticHelpers
+DEFobjCurrIf(glbl)
 DEFobjCurrIf(errmsg)
 
 static void display_status_(char *m, OM_uint32 code, int type)
@@ -108,28 +111,38 @@ static int read_all(int fd, char *buf, u
 {
     int     ret;
     char   *ptr;
-    fd_set  rfds;
     struct timeval tv;
+#ifdef USE_UNLIMITED_SELECT
+    fd_set  *pRfds = malloc(glbl.GetFdSetSize());
+#else
+    fd_set  rfds;
+    fd_set *pRfds = &rfds;
+#endif
 
     for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) {
-	    FD_ZERO(&rfds);
-	    FD_SET(fd, &rfds);
+	    FD_ZERO(pRfds);
+	    FD_SET(fd, pRfds);
 	    tv.tv_sec = 1;
 	    tv.tv_usec = 0;
 
-	    if ((ret = select(FD_SETSIZE, &rfds, NULL, NULL, &tv)) <= 0
-		|| !FD_ISSET(fd, &rfds))
+	    if ((ret = select(FD_SETSIZE, pRfds, NULL, NULL, &tv)) <= 0
+		|| !FD_ISSET(fd, pRfds)) {
+                    freeFdSet(pRfds);
 		    return ret;
+            }
 	    ret = recv(fd, ptr, nbyte, 0);
 	    if (ret < 0) {
 		    if (errno == EINTR)
 			    continue;
+                    freeFdSet(pRfds);
 		    return (ret);
 	    } else if (ret == 0) {
+                    freeFdSet(pRfds);
 		    return (ptr - buf);
 	    }
     }
 
+    freeFdSet(pRfds);
     return (ptr - buf);
 }
 
@@ -264,6 +277,7 @@ BEGINObjClassExit(gssutil, OBJ_IS_LOADAB
 CODESTARTObjClassExit(gssutil)
 	/* release objects we no longer need */
 	objRelease(errmsg, CORE_COMPONENT);
+	objRelease(glbl, CORE_COMPONENT);
 ENDObjClassExit(gssutil)
 
 
@@ -274,6 +288,7 @@ ENDObjClassExit(gssutil)
 BEGINAbstractObjClassInit(gssutil, 1, OBJ_IS_LOADABLE_MODULE) /* class, version - CHANGE class also in END MACRO! */
 	/* request objects we use */
 	CHKiRet(objUse(errmsg, CORE_COMPONENT));
+	CHKiRet(objUse(glbl, CORE_COMPONENT));
 ENDObjClassInit(gssutil)
 
 
diff -up rsyslog-3.22.1/plugins/imgssapi/imgssapi.c.orig rsyslog-3.22.1/plugins/imgssapi/imgssapi.c
--- rsyslog-3.22.1/plugins/imgssapi/imgssapi.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/plugins/imgssapi/imgssapi.c	2009-11-23 15:03:00.000000000 +0100
@@ -56,6 +56,7 @@
 #include "errmsg.h"
 #include "netstrm.h"
 #include "glbl.h"
+#include "unlimited_select.h"
 
 
 MODULE_TYPE_INPUT
@@ -415,15 +416,20 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_se
 		CHKiRet(netstrm.GetSock(pSess->pStrm, &fdSess)); // TODO: method access!
 		if (allowedMethods & ALLOWEDMETHOD_TCP) {
 			int len;
-			fd_set  fds;
 			struct timeval tv;
+#ifdef USE_UNLIMITED_SELECT
+                        fd_set *pFds = malloc(glbl.GetFdSetSize());
+#else
+                        fd_set fds;
+                        fd_set *pFds = &fds;
+#endif
 		
 			do {
-				FD_ZERO(&fds);
-				FD_SET(fdSess, &fds);
+				FD_ZERO(pFds);
+				FD_SET(fdSess, pFds);
 				tv.tv_sec = 1;
 				tv.tv_usec = 0;
-				ret = select(fdSess + 1, &fds, NULL, NULL, &tv);
+				ret = select(fdSess + 1, pFds, NULL, NULL, &tv);
 			} while (ret < 0 && errno == EINTR);
 			if (ret < 0) {
 				errmsg.LogError(0, RS_RET_ERR, "TCP session %p will be closed, error ignored\n", pSess);
@@ -476,6 +482,8 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_se
 				pGSess->allowedMethods = ALLOWEDMETHOD_TCP;
 				ABORT_FINALIZE(RS_RET_OK); // TODO: define good error codes
 			}
+
+                        freeFdSet(pFds);
 		}
 
 		context = &pGSess->gss_context;
diff -up rsyslog-3.22.1/plugins/imudp/imudp.c.orig rsyslog-3.22.1/plugins/imudp/imudp.c
--- rsyslog-3.22.1/plugins/imudp/imudp.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/plugins/imudp/imudp.c	2009-11-23 15:03:00.000000000 +0100
@@ -40,6 +40,7 @@
 #include "srUtils.h"
 #include "errmsg.h"
 #include "glbl.h"
+#include "unlimited_select.h"
 
 MODULE_TYPE_INPUT
 
@@ -136,13 +137,19 @@ BEGINrunInput
 	int maxfds;
 	int nfds;
 	int i;
-	fd_set readfds;
 	struct sockaddr_storage frominet;
 	socklen_t socklen;
 	uchar fromHost[NI_MAXHOST];
 	uchar fromHostIP[NI_MAXHOST];
 	uchar fromHostFQDN[NI_MAXHOST];
 	ssize_t l;
+#ifdef USE_UNLIMITED_SELECT
+        fd_set  *pReadfds = malloc(glbl.GetFdSetSize());
+#else
+        fd_set  readfds;
+        fd_set *pReadfds = &readfds;
+#endif
+
 CODESTARTrunInput
 	/* this is an endless loop - it is terminated when the thread is
 	 * signalled to do so. This, however, is handled by the framework,
@@ -156,7 +163,7 @@ CODESTARTrunInput
 		 * is given without -a, we do not need to listen at all..
 		 */
 	        maxfds = 0;
-	        FD_ZERO (&readfds);
+	        FD_ZERO (pReadfds);
 
 		/* Add the UDP listen sockets to the list of read descriptors.
 		 */
@@ -165,7 +172,7 @@ CODESTARTrunInput
                                 if (udpLstnSocks[i+1] != -1) {
 					if(Debug)
 						net.debugListenInfo(udpLstnSocks[i+1], "UDP");
-                                        FD_SET(udpLstnSocks[i+1], &readfds);
+					FD_SET(udpLstnSocks[i+1], pReadfds);
 					if(udpLstnSocks[i+1]>maxfds) maxfds=udpLstnSocks[i+1];
 				}
                         }
@@ -173,17 +180,17 @@ CODESTARTrunInput
 		if(Debug) {
 			dbgprintf("--------imUDP calling select, active file descriptors (max %d): ", maxfds);
 			for (nfds = 0; nfds <= maxfds; ++nfds)
-				if ( FD_ISSET(nfds, &readfds) )
+				if ( FD_ISSET(nfds, pReadfds) )
 					dbgprintf("%d ", nfds);
 			dbgprintf("\n");
 		}
 
 		/* wait for io to become ready */
-		nfds = select(maxfds+1, (fd_set *) &readfds, NULL, NULL, NULL);
+		nfds = select(maxfds+1, (fd_set *) pReadfds, NULL, NULL, NULL);
 
 		if(udpLstnSocks != NULL) {
 		       for (i = 0; nfds && i < *udpLstnSocks; i++) {
-			       if (FD_ISSET(udpLstnSocks[i+1], &readfds)) {
+			       if (FD_ISSET(udpLstnSocks[i+1], pReadfds)) {
 				       socklen = sizeof(frominet);
 				       l = recvfrom(udpLstnSocks[i+1], (char*) pRcvBuf, iMaxLine, 0,
 						    (struct sockaddr *)&frominet, &socklen);
@@ -230,6 +237,7 @@ CODESTARTrunInput
 		}
 	}
 
+	freeFdSet(pReadfds);
 	return iRet;
 ENDrunInput
 
diff -up rsyslog-3.22.1/plugins/imuxsock/imuxsock.c.orig rsyslog-3.22.1/plugins/imuxsock/imuxsock.c
--- rsyslog-3.22.1/plugins/imuxsock/imuxsock.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/plugins/imuxsock/imuxsock.c	2009-11-23 15:03:00.000000000 +0100
@@ -42,6 +42,7 @@
 #include "errmsg.h"
 #include "net.h"
 #include "glbl.h"
+#include "unlimited_select.h"
 
 MODULE_TYPE_INPUT
 
@@ -243,7 +244,13 @@ BEGINrunInput
 	int nfds;
 	int i;
 	int fd;
-	fd_set readfds;
+#ifdef USE_UNLIMITED_SELECT
+        fd_set  *pReadfds = malloc(glbl.GetFdSetSize());
+#else
+        fd_set  readfds;
+        fd_set *pReadfds = &readfds;
+#endif
+
 CODESTARTrunInput
 	/* this is an endless loop - it is terminated when the thread is
 	 * signalled to do so. This, however, is handled by the framework,
@@ -257,11 +264,11 @@ CODESTARTrunInput
 		 * is given without -a, we do not need to listen at all..
 		 */
 	        maxfds = 0;
-	        FD_ZERO (&readfds);
+	        FD_ZERO (pReadfds);
 		/* Copy master connections */
 		for (i = startIndexUxLocalSockets; i < nfunix; i++) {
 			if (funix[i] != -1) {
-				FD_SET(funix[i], &readfds);
+				FD_SET(funix[i], pReadfds);
 				if (funix[i]>maxfds) maxfds=funix[i];
 			}
 		}
@@ -269,22 +276,23 @@ CODESTARTrunInput
 		if(Debug) {
 			dbgprintf("--------imuxsock calling select, active file descriptors (max %d): ", maxfds);
 			for (nfds= 0; nfds <= maxfds; ++nfds)
-				if ( FD_ISSET(nfds, &readfds) )
+				if ( FD_ISSET(nfds, pReadfds) )
 					dbgprintf("%d ", nfds);
 			dbgprintf("\n");
 		}
 
 		/* wait for io to become ready */
-		nfds = select(maxfds+1, (fd_set *) &readfds, NULL, NULL, NULL);
+		nfds = select(maxfds+1, (fd_set *) pReadfds, NULL, NULL, NULL);
 
 		for (i = 0; i < nfunix && nfds > 0; i++) {
-			if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) {
+			if ((fd = funix[i]) != -1 && FD_ISSET(fd, pReadfds)) {
 				readSocket(fd, i);
 				--nfds; /* indicate we have processed one */
 			}
 		}
 	}
 
+	freeFdSet(pReadfds);
 	RETiRet;
 ENDrunInput
 
diff -up rsyslog-3.22.1/runtime/Makefile.am.orig rsyslog-3.22.1/runtime/Makefile.am
--- rsyslog-3.22.1/runtime/Makefile.am.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/Makefile.am	2009-11-23 15:03:00.000000000 +0100
@@ -14,6 +14,7 @@ librsyslog_la_SOURCES = \
 	nsd.h \
 	glbl.h \
 	glbl.c \
+	unlimited_select.h \
 	conf.c \
 	conf.h \
 	msg.c \
diff -up rsyslog-3.22.1/runtime/glbl.c.orig rsyslog-3.22.1/runtime/glbl.c
--- rsyslog-3.22.1/runtime/glbl.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/glbl.c	2009-11-23 15:03:00.000000000 +0100
@@ -64,6 +64,9 @@ static uchar *pszDfltNetstrmDrvr = NULL;
 static uchar *pszDfltNetstrmDrvrCAF = NULL; /* default CA file for the netstrm driver */
 static uchar *pszDfltNetstrmDrvrKeyFile = NULL; /* default key file for the netstrm driver (server) */
 static uchar *pszDfltNetstrmDrvrCertFile = NULL; /* default cert file for the netstrm driver (server) */
+#ifdef USE_UNLIMITED_SELECT
+static int iFdSetSize = howmany(FD_SETSIZE, __NFDBITS) * sizeof (fd_mask); /* size of select() bitmask in bytes */
+#endif
 
 
 /* define a macro for the simple properties' set and get functions
@@ -93,6 +96,9 @@ SIMP_PROP(DisableDNS, bDisableDNS, int)
 SIMP_PROP(LocalDomain, LocalDomain, uchar*)
 SIMP_PROP(StripDomains, StripDomains, char**)
 SIMP_PROP(LocalHosts, LocalHosts, char**)
+#ifdef USE_UNLIMITED_SELECT
+SIMP_PROP(FdSetSize, iFdSetSize, int)
+#endif
 
 SIMP_PROP_SET(LocalHostName, LocalHostName, uchar*)
 SIMP_PROP_SET(DfltNetstrmDrvr, pszDfltNetstrmDrvr, uchar*) /* TODO: use custom function which frees existing value */
@@ -185,6 +191,9 @@ CODESTARTobjQueryInterface(glbl)
 	SIMP_PROP(DfltNetstrmDrvrCAF)
 	SIMP_PROP(DfltNetstrmDrvrKeyFile)
 	SIMP_PROP(DfltNetstrmDrvrCertFile)
+#ifdef USE_UNLIMITED_SELECT
+	SIMP_PROP(FdSetSize)
+#endif
 #undef	SIMP_PROP
 finalize_it:
 ENDobjQueryInterface(glbl)
@@ -216,6 +225,9 @@ static rsRetVal resetConfigVariables(uch
 		pszWorkDir = NULL;
 	}
 	bDropMalPTRMsgs = 0;
+#ifdef USE_UNLIMITED_SELECT
+	iFdSetSize = howmany(FD_SETSIZE, __NFDBITS) * sizeof (fd_mask);
+#endif
 	return RS_RET_OK;
 }
 
diff -up rsyslog-3.22.1/runtime/glbl.h.orig rsyslog-3.22.1/runtime/glbl.h
--- rsyslog-3.22.1/runtime/glbl.h.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/glbl.h	2009-11-23 15:03:00.000000000 +0100
@@ -53,9 +53,10 @@ BEGINinterface(glbl) /* name must also b
 	SIMP_PROP(DfltNetstrmDrvrCAF, uchar*)
 	SIMP_PROP(DfltNetstrmDrvrKeyFile, uchar*)
 	SIMP_PROP(DfltNetstrmDrvrCertFile, uchar*)
+	SIMP_PROP(FdSetSize, int)
 #undef	SIMP_PROP
 ENDinterface(glbl)
-#define glblCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+#define glblCURR_IF_VERSION 100 /* increment whenever you change the interface structure! */
 
 /* the remaining prototypes */
 PROTOTYPEObj(glbl);
diff -up rsyslog-3.22.1/runtime/nsdsel_ptcp.c.orig rsyslog-3.22.1/runtime/nsdsel_ptcp.c
--- rsyslog-3.22.1/runtime/nsdsel_ptcp.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/nsdsel_ptcp.c	2009-11-23 15:03:00.000000000 +0100
@@ -36,6 +36,7 @@
 #include "errmsg.h"
 #include "nsd_ptcp.h"
 #include "nsdsel_ptcp.h"
+#include "unlimited_select.h"
 
 /* static data */
 DEFobjStaticHelpers
@@ -47,14 +48,23 @@ DEFobjCurrIf(glbl)
  */
 BEGINobjConstruct(nsdsel_ptcp) /* be sure to specify the object type also in END macro! */
 	pThis->maxfds = 0;
+#ifdef USE_UNLIMITED_SELECT
+        pThis->pReadfds = calloc(1, glbl.GetFdSetSize());
+        pThis->pWritefds = calloc(1, glbl.GetFdSetSize());
+#else
 	FD_ZERO(&pThis->readfds);
 	FD_ZERO(&pThis->writefds);
+#endif
 ENDobjConstruct(nsdsel_ptcp)
 
 
 /* destructor for the nsdsel_ptcp object */
 BEGINobjDestruct(nsdsel_ptcp) /* be sure to specify the object type also in END and CODESTART macros! */
 CODESTARTobjDestruct(nsdsel_ptcp)
+#ifdef USE_UNLIMITED_SELECT
+	freeFdSet(pThis->pReadfds);
+	freeFdSet(pThis->pWritefds);
+#endif
 ENDobjDestruct(nsdsel_ptcp)
 
 
@@ -65,20 +75,27 @@ Add(nsdsel_t *pNsdsel, nsd_t *pNsd, nsds
 	DEFiRet;
 	nsdsel_ptcp_t *pThis = (nsdsel_ptcp_t*) pNsdsel;
 	nsd_ptcp_t *pSock = (nsd_ptcp_t*) pNsd;
+#ifdef USE_UNLIMITED_SELECT
+        fd_set *pReadfds = pThis->pReadfds;
+        fd_set *pWritefds = pThis->pWritefds;
+#else
+        fd_set *pReadfds = &pThis->readfds;
+        fd_set *pWritefds = &pThis->writefds;
+#endif
 
 	ISOBJ_TYPE_assert(pSock, nsd_ptcp);
 	ISOBJ_TYPE_assert(pThis, nsdsel_ptcp);
 
 	switch(waitOp) {
 		case NSDSEL_RD:
-			FD_SET(pSock->sock, &pThis->readfds);
+			FD_SET(pSock->sock, pReadfds);
 			break;
 		case NSDSEL_WR:
-			FD_SET(pSock->sock, &pThis->writefds);
+			FD_SET(pSock->sock, pWritefds);
 			break;
 		case NSDSEL_RDWR:
-			FD_SET(pSock->sock, &pThis->readfds);
-			FD_SET(pSock->sock, &pThis->writefds);
+			FD_SET(pSock->sock, pReadfds);
+			FD_SET(pSock->sock, pWritefds);
 			break;
 	}
 
@@ -98,6 +115,13 @@ Select(nsdsel_t *pNsdsel, int *piNumRead
 	DEFiRet;
 	int i;
 	nsdsel_ptcp_t *pThis = (nsdsel_ptcp_t*) pNsdsel;
+#ifdef USE_UNLIMITED_SELECT
+        fd_set *pReadfds = pThis->pReadfds;
+        fd_set *pWritefds = pThis->pWritefds;
+#else
+        fd_set *pReadfds = &pThis->readfds;
+        fd_set *pWritefds = &pThis->writefds;
+#endif
 
 	ISOBJ_TYPE_assert(pThis, nsdsel_ptcp);
 	assert(piNumReady != NULL);
@@ -106,13 +130,13 @@ Select(nsdsel_t *pNsdsel, int *piNumRead
 		// TODO: name in dbgprintf!
 		dbgprintf("--------<NSDSEL_PTCP> calling select, active fds (max %d): ", pThis->maxfds);
 		for(i = 0; i <= pThis->maxfds; ++i)
-			if(FD_ISSET(i, &pThis->readfds) || FD_ISSET(i, &pThis->writefds))
+			if(FD_ISSET(i, pReadfds) || FD_ISSET(i, pWritefds))
 				dbgprintf("%d ", i);
 		dbgprintf("\n");
 	}
 
 	/* now do the select */
-	*piNumReady = select(pThis->maxfds+1, &pThis->readfds, &pThis->writefds, NULL, NULL);
+	*piNumReady = select(pThis->maxfds+1, pReadfds, pWritefds, NULL, NULL);
 
 	RETiRet;
 }
@@ -125,6 +149,13 @@ IsReady(nsdsel_t *pNsdsel, nsd_t *pNsd, 
 	DEFiRet;
 	nsdsel_ptcp_t *pThis = (nsdsel_ptcp_t*) pNsdsel;
 	nsd_ptcp_t *pSock = (nsd_ptcp_t*) pNsd;
+#ifdef USE_UNLIMITED_SELECT
+        fd_set *pReadfds = pThis->pReadfds;
+        fd_set *pWritefds = pThis->pWritefds;
+#else
+        fd_set *pReadfds = &pThis->readfds;
+        fd_set *pWritefds = &pThis->writefds;
+#endif
 
 	ISOBJ_TYPE_assert(pThis, nsdsel_ptcp);
 	ISOBJ_TYPE_assert(pSock, nsd_ptcp);
@@ -132,14 +163,14 @@ IsReady(nsdsel_t *pNsdsel, nsd_t *pNsd, 
 
 	switch(waitOp) {
 		case NSDSEL_RD:
-			*pbIsReady = FD_ISSET(pSock->sock, &pThis->readfds);
+			*pbIsReady = FD_ISSET(pSock->sock, pReadfds);
 			break;
 		case NSDSEL_WR:
-			*pbIsReady = FD_ISSET(pSock->sock, &pThis->writefds);
+			*pbIsReady = FD_ISSET(pSock->sock, pWritefds);
 			break;
 		case NSDSEL_RDWR:
-			*pbIsReady =   FD_ISSET(pSock->sock, &pThis->readfds)
-				     | FD_ISSET(pSock->sock, &pThis->writefds);
+			*pbIsReady =   FD_ISSET(pSock->sock, pReadfds)
+				     | FD_ISSET(pSock->sock, pWritefds);
 			break;
 	}
 
diff -up rsyslog-3.22.1/runtime/nsdsel_ptcp.h.orig rsyslog-3.22.1/runtime/nsdsel_ptcp.h
--- rsyslog-3.22.1/runtime/nsdsel_ptcp.h.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/nsdsel_ptcp.h	2009-11-23 15:03:00.000000000 +0100
@@ -31,8 +31,13 @@ typedef nsdsel_if_t nsdsel_ptcp_if_t; /*
 struct nsdsel_ptcp_s {
 	BEGINobjInstance;	/* Data to implement generic object - MUST be the first data element! */
 	int maxfds;
+#ifdef USE_UNLIMITED_SELECT
+	fd_set *pReadfds;
+	fd_set *pWritefds;
+#else
 	fd_set readfds;
 	fd_set writefds;
+#endif
 };
 
 /* interface is defined in nsd.h, we just implement it! */
diff -up rsyslog-3.22.1/runtime/rsyslog.h.orig rsyslog-3.22.1/runtime/rsyslog.h
--- rsyslog-3.22.1/runtime/rsyslog.h.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/rsyslog.h	2009-11-23 15:03:00.000000000 +0100
@@ -253,6 +253,7 @@ enum rsRetVal_				/** return value. All 
 	RS_RET_ACCEPT_ERR = -2106, /**< error during accept() system call */
 	RS_RET_INVLD_TIME = -2107, /**< invalid timestamp (e.g. could not be parsed) */
 	RS_RET_CODE_ERR = -2109, /**< program code (internal) error */
+	RS_RET_ERR_RLIM_NOFILE = -2116, /**< error setting max. nbr open files process limit */
 	RS_RET_NONFATAL_CONFIG_ERR = -2123, /**< non-fatal error during config processing */
 
 	/* RainerScript error messages (range 1000.. 1999) */
diff -up rsyslog-3.22.1/runtime/unlimited_select.h.orig rsyslog-3.22.1/runtime/unlimited_select.h
--- rsyslog-3.22.1/runtime/unlimited_select.h.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/runtime/unlimited_select.h	2009-11-23 15:03:00.000000000 +0100
@@ -0,0 +1,45 @@
+/* unlimited_select.h
+ * Tweak the macros for accessing fd_set so that the select() syscall
+ * won't be limited to a particular number of file descriptors.
+ *
+ * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+
+#ifndef	UNLIMITED_SELECT_H_INCLUDED
+
+#include <string.h>
+#include <stdlib.h>
+#include <sys/select.h>
+#include "glbl.h"
+
+#ifdef USE_UNLIMITED_SELECT
+# undef FD_ZERO
+# define FD_ZERO(set) memset((set), 0, glbl.GetFdSetSize());
+#endif
+
+#ifdef USE_UNLIMITED_SELECT
+void freeFdSet(fd_set *p) {
+        free(p);
+}
+#else
+# define freeFdSet(x)
+#endif
+
+#endif /* #ifndef UNLIMITED_SELECT_H_INCLUDED */
diff -up rsyslog-3.22.1/tools/syslogd.c.orig rsyslog-3.22.1/tools/syslogd.c
--- rsyslog-3.22.1/tools/syslogd.c.orig	2009-11-23 15:03:00.000000000 +0100
+++ rsyslog-3.22.1/tools/syslogd.c	2009-11-23 15:03:00.000000000 +0100
@@ -82,6 +82,7 @@
 #include <sys/ioctl.h>
 #include <sys/wait.h>
 #include <sys/file.h>
+#include <sys/resource.h>
 
 #if HAVE_SYS_TIMESPEC_H
 # include <sys/timespec.h>
@@ -2039,6 +2040,35 @@ static rsRetVal setActionResumeInterval(
 }
 
 
+/* set the processes max number of files (upon configuration request)
+ * 2009-04-14 rgerhards
+ */
+static rsRetVal setMaxFiles(void __attribute__((unused)) *pVal, int iFiles)
+{
+	struct rlimit maxFiles;
+	char errStr[1024];
+	DEFiRet;
+
+	maxFiles.rlim_cur = iFiles;
+	maxFiles.rlim_max = iFiles;
+
+	if(setrlimit(RLIMIT_NOFILE, &maxFiles) < 0) {
+		/* NOTE: under valgrind, we seem to be unable to extend the size! */
+		rs_strerror_r(errno, errStr, sizeof(errStr));
+		errmsg.LogError(0, RS_RET_ERR_RLIM_NOFILE, "could not set process file limit to %d: %s [kernel max %ld]",
+				iFiles, errStr, (long) maxFiles.rlim_max);
+		ABORT_FINALIZE(RS_RET_ERR_RLIM_NOFILE);
+	}
+#ifdef USE_UNLIMITED_SELECT
+	glbl.SetFdSetSize(howmany(iFiles, __NFDBITS) * sizeof (fd_mask));
+#endif
+	dbgprintf("Max number of files set to %d [kernel max %ld].\n", iFiles, (long) maxFiles.rlim_max);
+
+finalize_it:
+	RETiRet;
+}
+
+
 /* set the processes umask (upon configuration request) */
 static rsRetVal setUmask(void __attribute__((unused)) *pVal, int iUmask)
 {
@@ -2756,6 +2786,7 @@ static rsRetVal loadBuildInModules(void)
 	CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, conf.doModLoad, NULL, NULL));
 	CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, conf.doIncludeLine, NULL, NULL));
 	CHKiRet(regCfSysLineHdlr((uchar *)"umask", 0, eCmdHdlrFileCreateMode, setUmask, NULL, NULL));
+	CHKiRet(regCfSysLineHdlr((uchar *)"maxopenfiles", 0, eCmdHdlrInt, setMaxFiles, NULL, NULL));
 	CHKiRet(regCfSysLineHdlr((uchar *)"debugprinttemplatelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintTemplateList, NULL));
 	CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintModuleList, NULL));
 	CHKiRet(regCfSysLineHdlr((uchar *)"debugprintcfsyslinehandlerlist", 0, eCmdHdlrBinary,