X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdaemon.c;h=bd91a1a3501b4c9c16d9ae8c8d1bcb8cf3d79dcb;hb=62b6b326338d5162b0f570eaeb8a227fbc5a9c62;hp=b6d1dc42aaa64625b3752589e406c43364d67c39;hpb=c702f2e50f49217947554387360b65ad8fdfc154;p=openldap
diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c
index b6d1dc42aa..bd91a1a350 100644
--- a/servers/slapd/daemon.c
+++ b/servers/slapd/daemon.c
@@ -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 .
+ *
+ * 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
+ * .
+ */
+/* 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"
@@ -15,14 +34,11 @@
#include
#include
-#include "ldap_pvt.h"
+#include "slap.h"
#include "ldap_pvt_thread.h"
#include "lutil.h"
-#include "slap.h"
-#ifdef LDAP_SYNCREPL
#include "ldap_rq.h"
-#endif
#ifdef HAVE_TCPD
#include
@@ -49,6 +65,7 @@ int slap_inet4or6 = AF_INET;
/* globals */
time_t starttime;
ber_socket_t dtblsize;
+slap_ssf_t local_ssf = LDAP_PVT_SASL_LOCAL_SSF;
Listener **slap_listeners = NULL;
@@ -66,10 +83,8 @@ 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;
static struct slap_daemon {
ldap_pvt_thread_mutex_t sd_mutex;
@@ -99,6 +114,7 @@ static struct slap_daemon {
#define LDAPS_SRVTYPE_PREFIX "service:ldaps://"
static char** slapd_srvurls = NULL;
static SLPHandle slapd_hslp = 0;
+int slapd_register_slp = 0;
void slapd_slp_init( const char* urls ) {
int i;
@@ -196,8 +212,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 ));
@@ -210,44 +231,34 @@ 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 );
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL1,
- "slapd_add: added %ld%s%s\n", (long)s,
- FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
- FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: added %ld%s%s\n",
(long) s,
FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
-#endif
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
}
/*
* 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,
- "slapd_remove: removing %ld%s%s\n", (long) s,
- FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
- FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: removing %ld%s%s\n",
(long) s,
FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
-#endif
FD_CLR( s, &slap_daemon.sd_actives );
FD_CLR( s, &slap_daemon.sd_readers );
FD_CLR( s, &slap_daemon.sd_writers );
@@ -321,12 +332,8 @@ void slapd_set_read(ber_socket_t s, int wake) {
}
static void slapd_close(ber_socket_t s) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL1, "slapd_close: closing %ld\n", (long)s, 0, 0);
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: closing %ld\n",
(long) s, 0, 0 );
-#endif
tcp_close(s);
}
@@ -451,15 +458,9 @@ static int slap_get_listener_addresses(
if ( strlen(host) >
(sizeof(((struct sockaddr_un *)*sap)->sun_path) - 1) ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_get_listener_addresses: domain socket path (%s) "
- "too long in URL\n", host, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: domain socket path (%s) too long in URL",
host, 0, 0);
-#endif
goto errexit;
}
@@ -481,14 +482,8 @@ static int slap_get_listener_addresses(
snprintf(serv, sizeof serv, "%d", port);
if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_get_listener_addresses: getaddrinfo failed: %s\n",
- AC_GAI_STRERROR(err), 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "daemon: getaddrinfo failed: %s\n",
AC_GAI_STRERROR(err), 0, 0);
-#endif
return -1;
}
@@ -506,14 +501,8 @@ static int slap_get_listener_addresses(
for ( sai=res; sai; sai=sai->ai_next ) {
if( sai->ai_addr == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_get_listener_addresses: "
- "getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "slap_get_listener_addresses: "
"getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
-#endif
freeaddrinfo(res);
goto errexit;
}
@@ -563,13 +552,8 @@ static int slap_get_listener_addresses(
} else if ( !inet_aton( host, &in ) ) {
he = gethostbyname( host );
if( he == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_get_listener_addresses: invalid host %s\n", host, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: invalid host %s", host, 0, 0);
-#endif
return -1;
}
for (n = 0; he->h_addr_list[n]; n++) ;
@@ -631,15 +615,9 @@ static int slap_open_listener(
rc = ldap_url_parse( url, &lud );
if( rc != LDAP_URL_SUCCESS ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slap_open_listener: listen URL \"%s\" parse error %d\n",
- url, rc , 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: listen URL \"%s\" parse error=%d\n",
url, rc, 0 );
-#endif
return rc;
}
@@ -648,14 +626,9 @@ static int slap_open_listener(
#ifndef HAVE_TLS
if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: TLS is not supported (%s)\n", url, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: TLS not supported (%s)\n",
url, 0, 0 );
-#endif
ldap_free_urldesc( lud );
return -1;
}
@@ -684,13 +657,8 @@ static int slap_open_listener(
}
#else
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: URL scheme is not supported: %s\n", url, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "daemon: URL scheme not supported: %s",
url, 0, 0);
-#endif
ldap_free_urldesc( lud );
return -1;
#endif
@@ -731,15 +699,21 @@ static int slap_open_listener(
psal = sal;
while ( *sal != NULL ) {
+ char *af;
switch( (*sal)->sa_family ) {
case AF_INET:
+ af = "IPv4";
+ break;
#ifdef LDAP_PF_INET6
case AF_INET6:
+ af = "IPv6";
+ break;
#endif
#ifdef LDAP_PF_LOCAL
case AF_LOCAL:
-#endif
+ af = "Local";
break;
+#endif
default:
sal++;
continue;
@@ -750,29 +724,17 @@ static int slap_open_listener(
l.sl_sd = socket( (*sal)->sa_family, socktype, 0);
if ( l.sl_sd == AC_SOCKET_INVALID ) {
int err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slap_open_listener: socket() failed errno=%d (%s)\n",
- err, sock_errstr(err), 0 );
-#else
Debug( LDAP_DEBUG_ANY,
- "daemon: socket() failed errno=%d (%s)\n", err,
- sock_errstr(err), 0 );
-#endif
+ "daemon: %s socket() failed errno=%d (%s)\n",
+ af, err, sock_errstr(err) );
sal++;
continue;
}
#ifndef HAVE_WINSOCK
if ( l.sl_sd >= dtblsize ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slap_open_listener: listener descriptor %ld is too "
- "great %ld\n", (long)l.sl_sd, (long)dtblsize, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
- "daemon: listener descriptor %ld is too great %ld\n",
- (long) l.sl_sd, (long) dtblsize, 0 );
-#endif
+ "daemon: listener descriptor %ld is too great %ld\n",
+ (long) l.sl_sd, (long) dtblsize, 0 );
tcp_close( l.sl_sd );
sal++;
continue;
@@ -788,19 +750,12 @@ static int slap_open_listener(
/* enable address reuse */
tmp = 1;
rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
- (char *) &tmp, sizeof(tmp) );
+ (char *) &tmp, sizeof(tmp) );
if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: setsockopt( %ld, SO_REUSEADDR ) "
- "failed errno %d (%s)\n", (long)l.sl_sd, err,
- sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
(long) l.sl_sd, err, sock_errstr(err) );
-#endif
}
#endif
}
@@ -818,15 +773,9 @@ static int slap_open_listener(
(char *) &tmp, sizeof(tmp) );
if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: setsockopt( %ld, IPV6_V6ONLY ) failed errno %d (%s)\n",
- (long)l.sl_sd, err, sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(IPV6_V6ONLY) failed errno=%d (%s)\n",
(long) l.sl_sd, err, sock_errstr(err) );
-#endif
}
#endif
addrlen = sizeof(struct sockaddr_in6);
@@ -841,14 +790,8 @@ static int slap_open_listener(
if (bind(l.sl_sd, *sal, addrlen)) {
err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: bind(%ld) failed errno=%d (%s)\n",
- (long)l.sl_sd, err, sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
(long) l.sl_sd, err, sock_errstr(err) );
-#endif
tcp_close( l.sl_sd );
sal++;
continue;
@@ -861,14 +804,8 @@ static int slap_open_listener(
#if 0 /* don't muck with socket perms */
if ( chmod( addr, l.sl_perms ) < 0 && crit ) {
int err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: fchmod(%ld) failed errno=%d (%s)\n",
- (long)l.sl_sd, err, sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY, "daemon: fchmod(%ld) failed errno=%d (%s)",
(long) l.sl_sd, err, sock_errstr(err) );
-#endif
tcp_close( l.sl_sd );
slap_free_listener_addresses(psal);
return -1;
@@ -914,14 +851,8 @@ static int slap_open_listener(
#endif /* LDAP_PF_INET6 */
default:
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_open_listener: unsupported address family (%d)\n",
- (int)(*sal)->sa_family, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "daemon: unsupported address family (%d)\n",
(int) (*sal)->sa_family, 0, 0 );
-#endif
break;
}
@@ -939,24 +870,13 @@ static int slap_open_listener(
if ( l.sl_url.bv_val == NULL )
{
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, RESULTS,
- "slap_open_listener: failed on %s\n", url, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE,
"slap_open_listener: failed on %s\n", url, 0, 0 );
-#endif
return -1;
}
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, RESULTS,
- "slap_open_listener: daemon initialized %s\n",
- l.sl_url.bv_val, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
l.sl_url.bv_val, 0, 0 );
-#endif
return 0;
}
@@ -968,13 +888,8 @@ int slapd_daemon_init( const char *urls )
int i, j, n, rc;
char **u;
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ARGS,
- "slapd_daemon_init: %s\n", urls ? urls : "", 0, 0 );
-#else
Debug( LDAP_DEBUG_ARGS, "daemon_init: %s\n",
urls ? urls : "", 0, 0 );
-#endif
if( (rc = sockinit()) != 0 ) {
return rc;
}
@@ -999,13 +914,8 @@ int slapd_daemon_init( const char *urls )
* this byte arrives.
*/
if( (rc = lutil_pair( wake_sds )) < 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slap_daemon_init: lutil_pair() failed rc=%d\n", rc, 0, 0);
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
-#endif
return rc;
}
@@ -1019,45 +929,25 @@ int slapd_daemon_init( const char *urls )
u = ldap_str2charray( urls, " " );
if( u == NULL || u[0] == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slap_daemon_init: no urls (%s) provided.\n", urls, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
urls, 0, 0 );
-#endif
return -1;
}
for( i=0; u[i] != NULL; i++ ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL1,
- "slap_daemon_init: listen on %s\n", u[i], 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n",
u[i], 0, 0 );
-#endif
}
if( i == 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_daemon_init: no listeners to open (%s)\n", urls, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n",
urls, 0, 0 );
-#endif
ldap_charray_free( u );
return -1;
}
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slap_daemon_init: %d listeners to open...\n", i, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners to open...\n",
i, 0, 0 );
-#endif
slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) );
for(n = 0, j = 0; u[n]; n++ ) {
@@ -1068,17 +958,14 @@ int slapd_daemon_init( const char *urls )
}
slap_listeners[j] = NULL;
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL1,
- "slap_daemon_init: %d listeners opened\n", i, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners opened\n",
i, 0, 0 );
-#endif
#ifdef HAVE_SLP
- slapd_slp_init( urls );
- slapd_slp_reg();
+ if( slapd_register_slp ) {
+ slapd_slp_init( urls );
+ slapd_slp_reg();
+ }
#endif
ldap_charray_free( u );
@@ -1096,8 +983,10 @@ slapd_daemon_destroy(void)
sockdestroy();
#ifdef HAVE_SLP
- slapd_slp_dereg();
- slapd_slp_deinit();
+ if( slapd_register_slp ) {
+ slapd_slp_dereg();
+ slapd_slp_deinit();
+ }
#endif
return 0;
@@ -1114,7 +1003,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 );
@@ -1166,7 +1055,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
@@ -1195,14 +1084,9 @@ slapd_daemon_task(
if ( i < l ) {
/* We are already listening to in6addr_any */
-#ifdef NEW_LOGGING
- LDAP_LOG(CONNECTION, WARNING,
- "slapd_daemon_task: Attempt to listen to 0.0.0.0 failed, already listening on ::, assuming IPv4 included\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS,
"daemon: Attempt to listen to 0.0.0.0 failed, already listening on ::, assuming IPv4 included\n",
0, 0, 0 );
-#endif
slapd_close( slap_listeners[l]->sl_sd );
slap_listeners[l]->sl_sd = AC_SOCKET_INVALID;
continue;
@@ -1210,20 +1094,14 @@ slapd_daemon_task(
}
}
#endif
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slapd_daemon_task: listen( %s, 5 ) failed errno=%d (%s)\n",
- slap_listeners[l]->sl_url.bv_val, err, sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: listen(%s, 5) failed errno=%d (%s)\n",
slap_listeners[l]->sl_url.bv_val, err,
sock_errstr(err) );
-#endif
return( (void*)-1 );
}
- slapd_add( slap_listeners[l]->sl_sd );
+ slapd_add( slap_listeners[l]->sl_sd, 0 );
}
#ifdef HAVE_NT_SERVICE_MANAGER
@@ -1250,11 +1128,9 @@ slapd_daemon_task(
struct timeval tv;
struct timeval *tvp;
-#ifdef LDAP_SYNCREPL
struct timeval *cat;
time_t tdelta = 1;
struct re_s* rtask;
-#endif
now = slap_get_time();
if( ( global_idletimeout > 0 ) &&
@@ -1272,7 +1148,7 @@ slapd_daemon_task(
if( slapd_gentle_shutdown == 1 ) {
Debug( LDAP_DEBUG_ANY, "slapd gentle shutdown\n", 0, 0, 0 );
close_listeners( 1 );
- global_restrictops |= SLAP_RESTRICT_OP_WRITES;
+ frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
slapd_gentle_shutdown = 2;
}
@@ -1329,58 +1205,52 @@ slapd_daemon_task(
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
- if ( !at )
- at = ldap_pvt_thread_pool_backload(&connection_pool);
-
- tvp = at ? &tv : NULL;
+ if ( at
+#if defined(HAVE_YIELDING_SELECT) || defined(NO_THREADS)
+ && ( tv.tv_sec || tv.tv_usec )
+#endif
+ )
+ tvp = &tv;
+ else
+ tvp = NULL;
-#ifdef LDAP_SYNCREPL
ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
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 );
+ ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
}
rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
}
- rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
if ( cat != NULL ) {
time_t diff = difftime( cat->tv_sec, now );
if ( diff == 0 )
diff = tdelta;
- if ( tvp == NULL )
- tvp = &tv;
- if ( diff < tv.tv_sec ) {
+ if ( tvp == NULL || diff < tv.tv_sec ) {
tv.tv_sec = diff;
tv.tv_usec = 0;
+ tvp = &tv;
}
}
-#endif
for ( l = 0; slap_listeners[l] != NULL; l++ ) {
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ||
slap_listeners[l]->sl_is_mute )
continue;
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL1,
- "slapd_daemon_task: select: listen=%d "
- "active_threads=%d tvp=%s\n",
- slap_listeners[l]->sl_sd, at, tvp == NULL ? "NULL" : "zero" );
-#else
Debug( LDAP_DEBUG_CONNS,
"daemon: select: listen=%d active_threads=%d tvp=%s\n",
slap_listeners[l]->sl_sd, at,
tvp == NULL ? "NULL" : "zero" );
-#endif
}
switch(ns = select( nfds, &readfds,
@@ -1406,15 +1276,9 @@ slapd_daemon_task(
}
if( err != EINTR ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, INFO,
- "slapd_daemon_task: select failed (%d): %s\n",
- err, sock_errstr(err), 0 );
-#else
Debug( LDAP_DEBUG_CONNS,
"daemon: select failed (%d): %s\n",
err, sock_errstr(err), 0 );
-#endif
slapd_shutdown = 2;
}
}
@@ -1422,13 +1286,8 @@ slapd_daemon_task(
case 0: /* timeout - let threads run */
ebadf = 0;
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- "slapd_daemon_task: select timeout - yielding\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n",
0, 0, 0 );
-#endif
ldap_pvt_thread_yield();
continue;
@@ -1437,13 +1296,8 @@ slapd_daemon_task(
if( slapd_shutdown ) continue;
ebadf = 0;
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- "slapd_daemon_task: activity on %d descriptors\n", ns, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: activity on %d descriptors\n",
ns, 0, 0 );
-#endif
/* FALL THRU */
}
@@ -1461,7 +1315,7 @@ slapd_daemon_task(
socklen_t len = sizeof(from);
long id;
slap_ssf_t ssf = 0;
- char *authid = NULL;
+ struct berval authid = BER_BVNULL;
#ifdef SLAPD_RLOOKUPS
char hbuf[NI_MAXHOST];
#endif
@@ -1469,11 +1323,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';
@@ -1491,10 +1346,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], "", "",
- 2, 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;
@@ -1505,6 +1360,11 @@ slapd_daemon_task(
FD_CLR( slap_listeners[l]->sl_sd, &readfds );
FD_CLR( slap_listeners[l]->sl_sd, &writefds );
+# ifdef LDAP_PF_LOCAL
+ /* FIXME: apparently accept doesn't fill
+ * the sun_path sun_path member */
+ from.sa_un_addr.sun_path[0] = '\0';
+# endif /* LDAP_PF_LOCAL */
s = accept( slap_listeners[l]->sl_sd,
(struct sockaddr *) &from, &len );
if ( s == AC_SOCKET_INVALID ) {
@@ -1526,17 +1386,10 @@ slapd_daemon_task(
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
}
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, 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
ldap_pvt_thread_yield();
continue;
}
@@ -1544,15 +1397,9 @@ slapd_daemon_task(
#ifndef HAVE_WINSOCK
/* make sure descriptor number isn't too great */
if ( s >= dtblsize ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slapd_daemon_task: %ld beyond descriptor table size %ld\n",
- (long)s, (long)dtblsize, 0 );
-#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();
@@ -1586,16 +1433,9 @@ slapd_daemon_task(
(char *) &tmp, sizeof(tmp) );
if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slapd_daemon_task: setsockopt( %ld, SO_KEEPALIVE)"
- " failed errno=%d (%s)\n",
- (long)s, err, sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
"errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
-#endif
}
#endif
#ifdef TCP_NODELAY
@@ -1605,42 +1445,39 @@ slapd_daemon_task(
(char *)&tmp, sizeof(tmp) );
if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slapd_daemon_task: setsockopt( %ld, "
- "TCP_NODELAY) failed errno=%d (%s)\n",
- (long)s, err, sock_errstr(err) );
-#else
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(TCP_NODELAY) failed "
"errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
-#endif
}
#endif
}
#endif
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL1,
- "slapd_daemon_task: new connection on %ld\n", (long)s, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: new connection on %ld\n",
(long) s, 0, 0 );
-#endif
switch ( from.sa_addr.sa_family ) {
# ifdef LDAP_PF_LOCAL
case AF_LOCAL:
+ /* FIXME: apparently accept doesn't fill
+ * the sun_path sun_path member */
+ if ( from.sa_un_addr.sun_path[0] == '\0' ) {
+ AC_MEMCPY( from.sa_un_addr.sun_path,
+ slap_listeners[l]->sl_sa.sa_un_addr.sun_path,
+ sizeof( from.sa_un_addr.sun_path ) );
+ }
+
sprintf( peername, "PATH=%s", from.sa_un_addr.sun_path );
- ssf = LDAP_PVT_SASL_LOCAL_SSF;
+ ssf = local_ssf;
{
uid_t uid;
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);
}
@@ -1724,31 +1561,22 @@ slapd_daemon_task(
dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
peername,
#ifdef HAVE_TLS
- slap_listeners[l]->sl_is_tls,
+ slap_listeners[l]->sl_is_tls ? CONN_IS_TLS : 0,
#else
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
- LDAP_LOG( CONNECTION, INFO,
- "slapd_daemon_task: "
- "connection_init(%ld, %s, %s) "
- "failed.\n",
- (long)s, peername,
- slap_listeners[l]->sl_name.bv_val );
-#else
Debug( LDAP_DEBUG_ANY,
"daemon: connection_init(%ld, %s, %s) "
"failed.\n",
(long) s,
peername,
slap_listeners[l]->sl_name.bv_val );
-#endif
slapd_close(s);
continue;
}
@@ -1760,35 +1588,20 @@ slapd_daemon_task(
slap_listeners[l]->sl_name.bv_val,
0 );
- slapd_add( s );
+ slapd_add( s, 1 );
continue;
}
#ifdef LDAP_DEBUG
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- "slapd_daemon_task: activity on ", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
-#endif
#ifdef HAVE_WINSOCK
for ( i = 0; i < readfds.fd_count; i++ ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- " %d%s", readfds.fd_array[i], "r", 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS, " %d%s",
readfds.fd_array[i], "r", 0 );
-#endif
}
for ( i = 0; i < writefds.fd_count; i++ ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- " %d%s", writefds.fd_array[i], "w" , 0 );
-#else
Debug( LDAP_DEBUG_CONNS, " %d%s",
writefds.fd_array[i], "w", 0 );
-#endif
}
#else
@@ -1798,21 +1611,12 @@ slapd_daemon_task(
r = FD_ISSET( i, &readfds );
w = FD_ISSET( i, &writefds );
if ( r || w ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- " %d%s%s", i, r ? "r" : "", w ? "w" : "" );
-#else
Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
r ? "r" : "", w ? "w" : "" );
-#endif
}
}
#endif
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2, "\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
-#endif
#endif
@@ -1833,14 +1637,9 @@ slapd_daemon_task(
wd = i;
#endif
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- "slapd_daemon_task: write active on %d\n", wd, 0, 0 );
-#else
Debug( LDAP_DEBUG_CONNS,
"daemon: write active on %d\n",
wd, 0, 0 );
-#endif
/*
* NOTE: it is possible that the connection was closed
* and that the stream is now inactive.
@@ -1870,13 +1669,8 @@ slapd_daemon_task(
rd = i;
#endif
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, DETAIL2,
- "slapd_daemon_task: read activity on %d\n", rd, 0, 0 );
-#else
Debug ( LDAP_DEBUG_CONNS,
"daemon: read activity on %d\n", rd, 0, 0 );
-#endif
/*
* NOTE: it is possible that the connection was closed
* and that the stream is now inactive.
@@ -1892,47 +1686,24 @@ slapd_daemon_task(
}
if( slapd_shutdown == 1 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slapd_daemon_task: shutdown requested and initiated.\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE,
"daemon: shutdown requested and initiated.\n",
0, 0, 0 );
-#endif
} else if ( slapd_shutdown == 2 ) {
#ifdef HAVE_NT_SERVICE_MANAGER
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slapd_daemon_task: shutdown initiated by Service Manager.\n",
- 0, 0, 0);
-#else
Debug( LDAP_DEBUG_TRACE,
"daemon: shutdown initiated by Service Manager.\n",
0, 0, 0);
-#endif
#else /* !HAVE_NT_SERVICE_MANAGER */
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slapd_daemon_task: abnormal condition, "
- "shutdown initiated.\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE,
"daemon: abnormal condition, shutdown initiated.\n",
0, 0, 0 );
-#endif
#endif /* !HAVE_NT_SERVICE_MANAGER */
} else {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slapd_daemon_task: no active streams, shutdown initiated.\n",
- 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE,
"daemon: no active streams, shutdown initiated.\n",
0, 0, 0 );
-#endif
}
if( slapd_gentle_shutdown != 2 ) {
@@ -1943,18 +1714,13 @@ slapd_daemon_task(
slap_listeners = NULL;
if( !slapd_gentle_shutdown ) {
+ slapd_abrupt_shutdown = 1;
connections_shutdown();
}
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slapd_daemon_task: shutdown waiting for %d threads to terminate.\n",
- ldap_pvt_thread_pool_backload(&connection_pool), 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"slapd shutdown: waiting for %d threads to terminate\n",
ldap_pvt_thread_pool_backload(&connection_pool), 0, 0 );
-#endif
ldap_pvt_thread_pool_destroy(&connection_pool, 1);
return NULL;
@@ -1977,14 +1743,8 @@ int slapd_daemon( void )
0, slapd_daemon_task, NULL );
if ( rc != 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, ERR,
- "slapd_daemon: listener ldap_pvt_thread_create failed (%d).\n",
- rc, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
-#endif
return rc;
}
@@ -2052,10 +1812,7 @@ int sockdestroy(void)
RETSIGTYPE
slap_sig_shutdown( int sig )
{
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slap_sig_shutdown: signal %d\n", sig, 0, 0 );
-#else
+#if 0
Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
#endif
@@ -2067,13 +1824,7 @@ slap_sig_shutdown( int sig )
#if HAVE_NT_SERVICE_MANAGER && SIGBREAK
if (is_NT_Service && sig == SIGBREAK)
-#ifdef NEW_LOGGING
- LDAP_LOG( CONNECTION, CRIT,
- "slap_sig_shutdown: SIGBREAK ignored.\n", 0, 0, 0 );
-#else
- Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: SIGBREAK ignored.\n",
- 0, 0, 0);
-#endif
+ ;
else
#endif
#ifdef SIGHUP
@@ -2099,10 +1850,15 @@ 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) {
return slap_listeners;
}
+
+void slap_wake_listener()
+{
+ WAKE_LISTENER(1);
+}