]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/daemon.c
allow empty modlist
[openldap] / servers / slapd / daemon.c
index e6b5e157cb15da24fc61717b9c864d0980152b31..4f6875ff78ef79ebd5db8ba05065a56aa4ca3367 100644 (file)
@@ -82,11 +82,19 @@ static ber_socket_t wake_sds[2];
 static int emfile;
 
 static volatile int waking;
+#ifdef NO_THREADS
 #define WAKE_LISTENER(w)       do { \
        if ((w) && ++waking < 5) { \
                tcp_write( wake_sds[1], "0", 1 ); \
        } \
 } while(0)
+#else
+#define WAKE_LISTENER(w)       do { \
+       if (w) { \
+               tcp_write( wake_sds[1], "0", 1 ); \
+       } \
+} while(0)
+#endif
 
 volatile sig_atomic_t slapd_shutdown = 0;
 volatile sig_atomic_t slapd_gentle_shutdown = 0;
@@ -1113,6 +1121,12 @@ int slapd_daemon_init( const char *urls )
 
        Debug( LDAP_DEBUG_ARGS, "daemon_init: %s\n",
                urls ? urls : "<null>", 0, 0 );
+
+       ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
+#ifdef HAVE_TCPD
+       ldap_pvt_thread_mutex_init( &slap_daemon.tcpd_mutex );
+#endif
+
        if( (rc = sockinit()) != 0 ) return rc;
 
 #ifdef HAVE_SYSCONF
@@ -1143,6 +1157,8 @@ int slapd_daemon_init( const char *urls )
        if( u == NULL || u[0] == NULL ) {
                Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
                        urls, 0, 0 );
+               if ( u )
+                       ldap_charray_free( u );
                return -1;
        }
 
@@ -1182,11 +1198,6 @@ int slapd_daemon_init( const char *urls )
 #endif
 
        ldap_charray_free( u );
-       ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
-
-#ifdef HAVE_TCPD
-       ldap_pvt_thread_mutex_init( &slap_daemon.tcpd_mutex );
-#endif
 
        return !i;
 }
@@ -1832,21 +1843,17 @@ slapd_daemon_task(
                case -1: {      /* failure - try again */
                                int err = sock_errno();
 
-                               if( err == EBADF
-#ifdef WSAENOTSOCK
-                                       /* you'd think this would be EBADF */
-                                       || err == WSAENOTSOCK
-#endif
-                               ) {
-                                       if (++ebadf < SLAPD_EBADF_LIMIT)
-                                               continue;
-                               }
-
                                if( err != EINTR ) {
-                                       Debug( LDAP_DEBUG_CONNS,
-                                               "daemon: select failed (%d): %s\n",
-                                               err, sock_errstr(err), 0 );
-                                       slapd_shutdown = 2;
+                                       ebadf++;
+
+                                       /* Don't log unless we got it twice in a row */
+                                       if ( !( ebadf & 1 )) {
+                                               Debug( LDAP_DEBUG_ANY,
+                                                       "daemon: select failed count %d err (%d): %s\n",
+                                                       ebadf, err, sock_errstr(err) );
+                                       }
+                                       if ( ebadf >= SLAPD_EBADF_LIMIT )
+                                               slapd_shutdown = 2;
                                }
                        }
                        continue;
@@ -1972,23 +1979,21 @@ slapd_daemon_task(
                                "daemon: write active on %d\n",
                                wd, 0, 0 );
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
-                       connection_write_activate( wd );
-#else
                        /*
                         * NOTE: it is possible that the connection was closed
                         * and that the stream is now inactive.
                         * connection_write() must validate the stream is still
                         * active.
+                        *
+                        * ITS#4338: if the stream is invalid, there is no need to
+                        * close it here. It has already been closed in connection.c.
                         */
                        if ( connection_write( wd ) < 0 ) {
                                if ( SLAP_EVENT_IS_READ( wd )) {
                                        SLAP_EVENT_CLR_READ( (unsigned) wd );
                                        nrfds--;
                                }
-                               slapd_close( wd );
                        }
-#endif
                }
 
                for ( i = 0; nrfds > 0; i++ ) {
@@ -2014,9 +2019,7 @@ slapd_daemon_task(
 #ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        connection_read_activate( rd );
 #else
-                       if ( connection_read( rd ) < 0 ) {
-                               slapd_close( rd );
-                       }
+                       connection_read( rd );
 #endif
                }
 #else  /* !SLAP_EVENTS_ARE_INDEXED */
@@ -2066,7 +2069,7 @@ slapd_daemon_task(
 #endif
 
                for (i=0; i<ns; i++) {
-                       int rc = 1, fd;
+                       int rc = 1, fd, waswrite = 0;
 
                        if ( SLAP_EVENT_IS_LISTENER(i) ) {
 #ifdef SLAP_LIGHTWEIGHT_DISPATCHER
@@ -2096,9 +2099,8 @@ slapd_daemon_task(
                                                "daemon: write active on %d\n",
                                                fd, 0, 0 );
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
-                                       connection_write_activate( fd );
-#else
+                                       waswrite = 1;
+
                                        /*
                                         * NOTE: it is possible that the connection was closed
                                         * and that the stream is now inactive.
@@ -2106,12 +2108,11 @@ slapd_daemon_task(
                                         * active.
                                         */
                                        if ( connection_write( fd ) < 0 ) {
-                                               slapd_close( fd );
                                                continue;
                                        }
-#endif
                                }
-                               if( SLAP_EVENT_IS_READ( i ) ) {
+                               /* If event is a read or an error */
+                               if( SLAP_EVENT_IS_READ( i ) || !waswrite ) {
                                        Debug( LDAP_DEBUG_CONNS,
                                                "daemon: read active on %d\n",
                                                fd, 0, 0 );
@@ -2125,7 +2126,7 @@ slapd_daemon_task(
                                         * connection_read() must valid the stream is still
                                         * active.
                                         */
-                                       if ( connection_read( fd ) < 0 ) slapd_close( fd );
+                                       connection_read( fd );
 #endif
                                }
                        }