]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/daemon.c
don't send error with back-meta
[openldap] / servers / slapd / daemon.c
index 49007b612dd6b32dcd935aa46509cc751fa0f206..e6b5e157cb15da24fc61717b9c864d0980152b31 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -81,10 +81,9 @@ Listener **slap_listeners = NULL;
 static ber_socket_t wake_sds[2];
 static int emfile;
 
-static int waking;
+static volatile int waking;
 #define WAKE_LISTENER(w)       do { \
-       if ((w) && waking < 5) { \
-               waking++; \
+       if ((w) && ++waking < 5) { \
                tcp_write( wake_sds[1], "0", 1 ); \
        } \
 } while(0)
@@ -216,7 +215,7 @@ static struct slap_daemon {
 # define SLAP_EVENT_IS_READ(i) SLAP_CHK_EVENT((i), EPOLLIN)
 # define SLAP_EVENT_IS_WRITE(i)        SLAP_CHK_EVENT((i), EPOLLOUT)
 # define SLAP_EVENT_IS_LISTENER(i)     SLAP_EV_LISTENER(revents[(i)].data.ptr)
-# define SLAP_EVENT_LISTENER(i)        (revents[(i)].data.ptr)
+# define SLAP_EVENT_LISTENER(i)        ((Listener *)(revents[(i)].data.ptr))
 
 # define SLAP_EVENT_FD(i)      SLAP_EV_PTRFD(revents[(i)].data.ptr)
 
@@ -283,7 +282,7 @@ static struct slap_daemon {
        if (!SLAP_SOCK_IS_WRITE(fd)) { FD_SET((fd), &slap_daemon.sd_writers); } \
 } while(0)
 
-#  define SLAP_ADDTEST(s)      do { } while 0
+#  define SLAP_ADDTEST(s)      
 #  define SLAP_EVENT_MAX       dtblsize
 # else
 #  define SLAP_SOCK_SET_READ(fd)       FD_SET((fd), &slap_daemon.sd_readers)
@@ -1099,21 +1098,6 @@ static int slap_open_listener(
                return -1;
        }
 
-#ifdef LDAP_CONNECTIONLESS
-       if( l.sl_is_udp ) {
-               long id = connection_init( l.sl_sd, &l, "", "", CONN_IS_UDP,
-                       (slap_ssf_t) 0, NULL );
-
-               if( id < 0 ) {
-                       Debug( LDAP_DEBUG_TRACE,
-                               "slap_open_listener: connectionless init failed on %s (%d)\n",
-                               url, l.sl_sd, 0 );
-                       return -1;
-               }
-               l.sl_is_udp++;
-       }
-#endif
-
        Debug( LDAP_DEBUG_TRACE, "daemon: listener initialized %s\n",
                l.sl_url.bv_val, 0, 0 );
        return 0;
@@ -1613,10 +1597,8 @@ slapd_daemon_task(
                 * listening port. The listen() and accept() calls
                 * are unnecessary.
                 */
-               if ( slap_listeners[l]->sl_is_udp ) {
-                       slapd_add( slap_listeners[l]->sl_sd, 1, slap_listeners[l] );
+               if ( slap_listeners[l]->sl_is_udp )
                        continue;
-               }
 #endif
 
                if ( listen( slap_listeners[l]->sl_sd, SLAPD_LISTEN_BACKLOG ) == -1 ) {
@@ -1679,7 +1661,7 @@ slapd_daemon_task(
        }
 
 #ifdef HAVE_NT_SERVICE_MANAGER
-       if ( started_event != NULL ) }
+       if ( started_event != NULL ) {
                ldap_pvt_thread_cond_signal( &started_event );
        }
 #endif
@@ -1730,9 +1712,13 @@ slapd_daemon_task(
                        ber_socket_t active;
 
                        if( slapd_gentle_shutdown == 1 ) {
+                               BackendDB *be;
                                Debug( LDAP_DEBUG_ANY, "slapd gentle shutdown\n", 0, 0, 0 );
                                close_listeners( 1 );
                                frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
+                               LDAP_STAILQ_FOREACH(be, &backendDB, be_next) {
+                                       be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
+                               }
                                slapd_gentle_shutdown = 2;
                        }
 
@@ -1740,7 +1726,7 @@ slapd_daemon_task(
                        active = slap_daemon.sd_nactives;
                        ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
                        if( active == 0 ) {
-                               slapd_shutdown = 2;
+                               slapd_shutdown = 1;
                                break;
                        }
                }
@@ -1887,14 +1873,11 @@ slapd_daemon_task(
 
 #if SLAP_EVENTS_ARE_INDEXED
                if ( SLAP_EVENT_IS_READ( wake_sds[0] )) {
+                       char c[BUFSIZ];
                        SLAP_EVENT_CLR_READ( wake_sds[0] );
-                       ns--;
-                       {
-                               char c[BUFSIZ];
-                               tcp_read( wake_sds[0], c, sizeof(c) );
-                       }
-                       Debug( LDAP_DEBUG_CONNS, "daemon: waked\n", 0, 0, 0 );
                        waking = 0;
+                       tcp_read( wake_sds[0], c, sizeof(c) );
+                       Debug( LDAP_DEBUG_CONNS, "daemon: waked\n", 0, 0, 0 );
                        continue;
                }
 
@@ -2103,8 +2086,8 @@ slapd_daemon_task(
                                /* Handle wake events */
                                if ( fd == wake_sds[0] ) {
                                        char c[BUFSIZ];
-                                       tcp_read( wake_sds[0], c, sizeof(c) );
                                        waking = 0;
+                                       tcp_read( wake_sds[0], c, sizeof(c) );
                                        break;
                                }
 
@@ -2194,11 +2177,41 @@ slapd_daemon_task(
 }
 
 
+#ifdef LDAP_CONNECTIONLESS
+static int connectionless_init(void)
+{
+       int l;
+
+       for ( l = 0; slap_listeners[l] != NULL; l++ ) {
+               Listener *lr = slap_listeners[l];
+               long id;
+
+               if( !lr->sl_is_udp ) {
+                       continue;
+               }
+
+               id = connection_init( lr->sl_sd, lr, "", "", CONN_IS_UDP, (slap_ssf_t) 0, NULL );
+
+               if( id < 0 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "connectionless_init: failed on %s (%d)\n", lr->sl_url, lr->sl_sd, 0 );
+                       return -1;
+               }
+               lr->sl_is_udp++;
+       }
+
+       return 0;
+}
+#endif /* LDAP_CONNECTIONLESS */
+
 int slapd_daemon( void )
 {
        int rc;
 
        connections_init();
+#ifdef LDAP_CONNECTIONLESS
+       connectionless_init();
+#endif
 
 #define SLAPD_LISTENER_THREAD 1
 #if defined( SLAPD_LISTENER_THREAD )