return -1;
}
- sai = res;
sap = *sal;
+ *sap = NULL;
+
+ for ( sai=res; sai; sai=sai->ai_next ) {
+ if( sai->ai_addr == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
+ "slap_get_listener_addresses: "
+ "getaddrinfo ai_addr is NULL?\n" ));
+#else
+ Debug( LDAP_DEBUG_ANY, "slap_get_listener_addresses: "
+ "getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
+#endif
+ freeaddrinfo(res);
+ goto errexit;
+ }
- do {
switch (sai->ai_family) {
# ifdef LDAP_PF_INET6
case AF_INET6:
*sap = NULL;
break;
}
+
if (*sap != NULL) {
(*sap)->sa_family = sai->ai_family;
sap++;
+ *sap = NULL;
}
- } while ((sai = sai->ai_next) != NULL);
+ }
- *sap = NULL;
freeaddrinfo(res);
#else
struct in_addr in;
#endif
} else {
#ifdef LDAP_CONNECTIONLESS
- if ( tmp == LDAP_PROTO_UDP )
- l.sl_is_udp = 1;
+ l.sl_is_udp = ( tmp == LDAP_PROTO_UDP );
#endif
if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
|| strcmp(lud->lud_host, "*") == 0 )
ber_socket_t nfds;
#define SLAPD_EBADF_LIMIT 16
int ebadf = 0;
+ int emfile = 0;
#define SLAPD_IDLE_CHECK_LIMIT 4
time_t now = slap_get_time();
Sockaddr from;
#if defined(SLAPD_RLOOKUPS)
- struct hostent *hp;
+ struct hostent *hp;
#endif
struct timeval zero;
struct timeval *tvp;
- if( global_idletimeout > 0 && difftime(
+ if( emfile || ( global_idletimeout > 0 && difftime(
last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT,
- now ) < 0 )
+ now ) < 0 ))
{
connections_timeout_idle(now);
}
(struct sockaddr *) &from, &len );
if ( s == AC_SOCKET_INVALID ) {
int err = sock_errno();
+
+#ifdef EMFILE
+ if( err == EMFILE ) {
+ emfile++;
+ } else
+#endif
+#ifdef ENFILE
+ if( err == ENFILE ) {
+ emfile++;
+ } else
+#endif
+ {
+ emfile=0;
+ }
+
+ if( emfile < 3 ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
- "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n",
- (long)slap_listeners[l]->sl_sd, err, sock_errstr(err) ));
+ LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
+ "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n",
+ (long)slap_listeners[l]->sl_sd, err, sock_errstr(err) ));
#else
- Debug( LDAP_DEBUG_ANY,
- "daemon: accept(%ld) failed errno=%d (%s)\n",
- (long) slap_listeners[l]->sl_sd, err,
- sock_errstr(err) );
-#endif
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: accept(%ld) failed errno=%d (%s)\n",
+ (long) slap_listeners[l]->sl_sd, err,
+ sock_errstr(err) );
+#endif
+ } else {
+ /* prevent busy loop */
+# ifdef HAVE_USLEEP
+ if( emfile % 4 == 3 ) usleep( 250 );
+# else
+ if( emfile % 8 == 7 ) sleep( 1 );
+# endif
+ }
+
ldap_pvt_thread_yield();
continue;
}
+ emfile = 0;
#ifndef HAVE_WINSOCK
/* make sure descriptor number isn't too great */
if ( s >= dtblsize ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
- "slapd_daemon_task: %ld beyond descriptor table size %ld\n",
- (long)s, (long)dtblsize ));
+ "slapd_daemon_task: %ld beyond descriptor table size %ld\n",
+ (long)s, (long)dtblsize ));
#else
Debug( LDAP_DEBUG_ANY,
"daemon: %ld beyond descriptor table size %ld\n",
(long) s, (long) dtblsize, 0 );
#endif
+
slapd_close(s);
ldap_pvt_thread_yield();
continue;