diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index ce75795f47a06080e8ca87719d68a72e28d77f33..decb92978cacefe20e5319ac5bf0233232ab986a 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -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). diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 739c32e6d9f44deb5ff45d1e5700d7522c5f232a..b3e191d61a4cfcbc130f1c24f1bcf9abb98b4353 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -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; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index acedf1659b028a4774d68f858274ea0640ab19fb..e0c6604a15cf44526a95998a6b19bcbddfe83dfc 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -27,6 +27,7 @@ #define PROTO_SLAP_H #include +#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);