]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/daemon.c
Cleanup result handling
[openldap] / servers / slapd / daemon.c
index efcf1b1992396073b5691e14ce26b7a20b08ed77..97556de00e0aa2ccae56dde3a0cf399c7f184b60 100644 (file)
@@ -1,7 +1,26 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2004 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
  */
 
 #include "portable.h"
@@ -64,9 +83,6 @@ static int waking;
 do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0)
 #endif
 
-#ifndef HAVE_WINSOCK
-static
-#endif
 volatile sig_atomic_t slapd_shutdown = 0, slapd_gentle_shutdown = 0;
 volatile sig_atomic_t slapd_abrupt_shutdown = 0;
 
@@ -195,8 +211,13 @@ void slapd_slp_dereg() {
 
 /*
  * Add a descriptor to daemon control
+ *
+ * If isactive, the descriptor is a live server session and is subject
+ * to idletimeout control. Otherwise, the descriptor is a passive
+ * listener or an outbound client session, and not subject to
+ * idletimeout.
  */
-static void slapd_add(ber_socket_t s) {
+static void slapd_add(ber_socket_t s, int isactive) {
        ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
 
        assert( !FD_ISSET( s, &slap_daemon.sd_actives ));
@@ -209,7 +230,9 @@ static void slapd_add(ber_socket_t s) {
        }
 #endif
 
-       slap_daemon.sd_nactives++;
+       if ( isactive ) {
+               slap_daemon.sd_nactives++;
+       }
 
        FD_SET( s, &slap_daemon.sd_actives );
        FD_SET( s, &slap_daemon.sd_readers );
@@ -231,10 +254,12 @@ static void slapd_add(ber_socket_t s) {
 /*
  * Remove the descriptor from daemon control
  */
-void slapd_remove(ber_socket_t s, int wake) {
+void slapd_remove(ber_socket_t s, int wasactive, int wake) {
        ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
 
-       slap_daemon.sd_nactives--;
+       if ( wasactive ) {
+               slap_daemon.sd_nactives--;
+       }
 
 #ifdef NEW_LOGGING
        LDAP_LOG( CONNECTION, DETAIL1, 
@@ -1119,7 +1144,7 @@ close_listeners(
        for ( l = 0; slap_listeners[l] != NULL; l++ ) {
                if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
                        if ( remove )
-                               slapd_remove( slap_listeners[l]->sl_sd, 0 );
+                               slapd_remove( slap_listeners[l]->sl_sd, 0, 0 );
 #ifdef LDAP_PF_LOCAL
                        if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) {
                                unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path );
@@ -1171,7 +1196,7 @@ slapd_daemon_task(
                 * are unnecessary.
                 */
                if ( slap_listeners[l]->sl_is_udp ) {
-                       slapd_add( slap_listeners[l]->sl_sd );
+                       slapd_add( slap_listeners[l]->sl_sd, 1 );
                        continue;
                }
 #endif
@@ -1228,7 +1253,7 @@ slapd_daemon_task(
                        return( (void*)-1 );
                }
 
-               slapd_add( slap_listeners[l]->sl_sd );
+               slapd_add( slap_listeners[l]->sl_sd, 0 );
        }
 
 #ifdef HAVE_NT_SERVICE_MANAGER
@@ -1332,11 +1357,6 @@ slapd_daemon_task(
 
                ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
 
-               if ( !at ) {
-                       at = ldap_pvt_thread_pool_backload(&connection_pool) -
-                                ldap_pvt_runqueue_persistent_backload( &syncrepl_rq );
-               }
-
                if ( at 
 #if defined(HAVE_YIELDING_SELECT) || defined(NO_THREADS)
                        &&  ( tv.tv_sec || tv.tv_usec )
@@ -1350,10 +1370,10 @@ slapd_daemon_task(
                rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
                while ( cat && cat->tv_sec && cat->tv_sec <= now ) {
                        if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
-                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
+                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
                        } else {
                                ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask );
-                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
+                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
                                ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
                                ldap_pvt_thread_pool_submit( &connection_pool,
                                                                                        rtask->routine, (void *) rtask );
@@ -1470,7 +1490,7 @@ slapd_daemon_task(
                        socklen_t len = sizeof(from);
                        long id;
                        slap_ssf_t ssf = 0;
-                       char *authid = NULL;
+                       struct berval authid = { 0, NULL };
 #ifdef SLAPD_RLOOKUPS
                        char hbuf[NI_MAXHOST];
 #endif
@@ -1478,11 +1498,12 @@ slapd_daemon_task(
                        char    *dnsname = NULL;
                        char    *peeraddr = NULL;
 #ifdef LDAP_PF_LOCAL
-                       char    peername[MAXPATHLEN + sizeof("PATH=")];
+                       char peername[MAXPATHLEN + sizeof("PATH=")];
 #elif defined(LDAP_PF_INET6)
-                       char    peername[sizeof("IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")];
+                       char peername[sizeof(
+                               "IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")];
 #else
-                       char    peername[sizeof("IP=255.255.255.255:65336")];
+                       char peername[sizeof("IP=255.255.255.255:65336")];
 #endif /* LDAP_PF_LOCAL */
 
                        peername[0] = '\0';
@@ -1500,10 +1521,10 @@ slapd_daemon_task(
                                 * of the slapd.
                                 */
                                if ( slap_listeners[l]->sl_is_udp < 2 ) {
-                                   id = connection_init(
-                                       slap_listeners[l]->sl_sd,
-                                       slap_listeners[l], "", "",
-                                       CONN_IS_UDP, ssf, authid );
+                                       id = connection_init(
+                                               slap_listeners[l]->sl_sd,
+                                               slap_listeners[l], "", "",
+                                               CONN_IS_UDP, ssf, NULL );
                                    slap_listeners[l]->sl_is_udp++;
                                }
                                continue;
@@ -1646,10 +1667,11 @@ slapd_daemon_task(
                                        gid_t gid;
 
                                        if( getpeereid( s, &uid, &gid ) == 0 ) {
-                                               authid = ch_malloc(
+                                               authid.bv_val = ch_malloc(
                                                        sizeof("uidnumber=4294967295+gidnumber=4294967295,"
-                                                               "cn=peercred,cn=external,cn=auth"));
-                                               sprintf(authid, "uidnumber=%d+gidnumber=%d,"
+                                                       "cn=peercred,cn=external,cn=auth"));
+                                               authid.bv_len = sprintf( authid.bv_val,
+                                                       "uidnumber=%d+gidnumber=%d,"
                                                        "cn=peercred,cn=external,cn=auth",
                                                        (int) uid, (int) gid);
                                        }
@@ -1738,9 +1760,9 @@ slapd_daemon_task(
                                0,
 #endif
                                ssf,
-                               authid );
+                               authid.bv_val ? &authid : NULL );
 
-                       if( authid ) ch_free(authid);
+                       if( authid.bv_val ) ch_free(authid.bv_val);
 
                        if( id < 0 ) {
 #ifdef NEW_LOGGING
@@ -1769,7 +1791,7 @@ slapd_daemon_task(
                                slap_listeners[l]->sl_name.bv_val,
                                0 );
 
-                       slapd_add( s );
+                       slapd_add( s, 1 );
                        continue;
                }
 
@@ -2105,8 +2127,8 @@ slap_sig_wake( int sig )
 }
 
 
-void slapd_add_internal(ber_socket_t s) {
-       slapd_add(s);
+void slapd_add_internal(ber_socket_t s, int isactive) {
+       slapd_add(s, isactive);
 }
 
 Listener ** slapd_get_listeners(void) {