Commit 2b540da0 authored by Lorenz Brun's avatar Lorenz Brun

Add limit to amount of allocated connections

This adds support for the -x option which limits the amount of space
allocated for connections on systems
with very high open file limits.
Signed-off-by: default avatarLorenz Brun <lorenz@brun.one>
parent 9eb94852
Pipeline #1254 passed with stage
in 25 minutes and 7 seconds
......@@ -37,6 +37,7 @@
#include "slap.h"
#include "ldap_pvt_thread.h"
#include "lber_types.h"
#include "lutil.h"
#include "ldap_rq.h"
......@@ -1830,7 +1831,7 @@ static int sockdestroy(void);
static int daemon_inited = 0;
int
slapd_daemon_init( const char *urls )
slapd_daemon_init( const char *urls, ber_socket_t maxConns )
{
int i, j, n, rc;
char **u;
......@@ -1863,6 +1864,10 @@ slapd_daemon_init( const char *urls )
dtblsize = FD_SETSIZE;
#endif /* ! HAVE_SYSCONF && ! HAVE_GETDTABLESIZE */
if (maxConns > 0 && dtblsize > maxConns) {
dtblsize = maxConns;
}
SETUP_CLOSE();
/* open a pipe (or something equivalent connected to itself).
......
......@@ -317,6 +317,7 @@ usage( char *name )
"\t-d level\tDebug level" "\n"
"\t-f filename\tConfiguration file\n"
"\t-F dir\tConfiguration directory\n"
"\t-x num\tMaximum number of connections\n"
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
"\t-g group\tGroup (id or name) to run as\n"
#endif
......@@ -358,6 +359,7 @@ int main( int argc, char **argv )
int i, no_detach = 0;
int rc = 1;
char *urls = NULL;
ber_socket_t maxConns = -1;
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
char *username = NULL;
char *groupname = NULL;
......@@ -465,7 +467,7 @@ int main( int argc, char **argv )
#endif
while ( (i = getopt( argc, argv,
"c:d:f:F:h:n:o:s:tT:V"
"c:d:f:F:x:h:n:o:s:tT:V"
#ifdef LDAP_PF_INET6
"46"
#endif
......@@ -644,6 +646,10 @@ int main( int argc, char **argv )
version++;
break;
case 'x':
maxConns = (int) strtol(optarg, NULL, 10);
break;
case 'T':
if ( firstopt == 0 ) {
fprintf( stderr, "warning: \"-T %s\" "
......@@ -744,7 +750,7 @@ unhandled_option:;
global_host = ldap_pvt_get_fqdn( NULL );
ber_str2bv( global_host, 0, 0, &global_host_bv );
if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
if( check == CHECK_NONE && slapd_daemon_init( urls, maxConns ) != 0 ) {
rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
goto stop;
......
......@@ -27,6 +27,7 @@
#define PROTO_SLAP_H
#include <ldap_cdefs.h>
#include "lber_types.h"
#include "ldap_pvt.h"
LDAP_BEGIN_DECL
......@@ -877,7 +878,7 @@ LDAP_SLAPD_F (void) slap_queue_csn LDAP_P(( Operation *, struct berval * ));
* daemon.c
*/
LDAP_SLAPD_F (void) slapd_add_internal(ber_socket_t s, int isactive);
LDAP_SLAPD_F (int) slapd_daemon_init( const char *urls );
LDAP_SLAPD_F (int) slapd_daemon_init( const char *urls, ber_socket_t maxConn );
LDAP_SLAPD_F (int) slapd_daemon_resize( int newnum );
LDAP_SLAPD_F (int) slapd_daemon_destroy(void);
LDAP_SLAPD_F (int) slapd_daemon(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment