1998-08-09 10:28:45 +08:00
|
|
|
|
|
|
|
/* Revision history
|
|
|
|
*
|
|
|
|
* 5-Jun-96 hodges
|
|
|
|
* Added locking of new_conn_mutex when traversing the c[] array.
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/errno.h>
|
|
|
|
#include <ac/signal.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "ldapconfig.h"
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include "slap.h"
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/filio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#elif HAVE_SYS_IOCTL_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/ioctl.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
#ifdef LDAP_DEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
#else
|
|
|
|
#define assert( cond )
|
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_TCPD
|
1998-08-16 07:03:09 +08:00
|
|
|
#include <tcpd.h>
|
|
|
|
|
|
|
|
int allow_severity = LOG_INFO;
|
|
|
|
int deny_severity = LOG_NOTICE;
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* TCP Wrappers */
|
1998-08-16 07:03:09 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
int dtblsize;
|
|
|
|
Connection *c;
|
|
|
|
|
1998-12-21 02:16:03 +08:00
|
|
|
static volatile sig_atomic_t slapd_shutdown = 0;
|
1999-02-05 21:20:57 +08:00
|
|
|
|
1999-01-21 23:53:54 +08:00
|
|
|
/* a link to the slapd.conf configuration parameters */
|
|
|
|
extern char *slapd_pid_file;
|
|
|
|
extern char *slapd_args_file;
|
1999-01-05 23:40:58 +08:00
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
void *
|
1998-08-14 04:20:13 +08:00
|
|
|
slapd_daemon(
|
1999-03-17 11:56:25 +08:00
|
|
|
void *ptr
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
1999-03-17 11:56:25 +08:00
|
|
|
struct sockaddr_in *addr = ptr;
|
1998-08-09 08:43:13 +08:00
|
|
|
int i;
|
|
|
|
int tcps, ns;
|
|
|
|
fd_set readfds;
|
|
|
|
fd_set writefds;
|
|
|
|
FILE *fp;
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_SYSCONF
|
1998-08-18 07:26:25 +08:00
|
|
|
dtblsize = sysconf( _SC_OPEN_MAX );
|
1998-10-25 09:41:42 +08:00
|
|
|
#elif HAVE_GETDTABLESIZE
|
1998-08-18 07:26:25 +08:00
|
|
|
dtblsize = getdtablesize();
|
1998-10-25 09:41:42 +08:00
|
|
|
#else
|
|
|
|
dtblsize = FD_SETSIZE
|
|
|
|
#endif
|
|
|
|
|
1998-08-18 07:26:25 +08:00
|
|
|
#ifdef FD_SETSIZE
|
1998-08-09 09:05:15 +08:00
|
|
|
if(dtblsize > FD_SETSIZE) {
|
|
|
|
dtblsize = FD_SETSIZE;
|
|
|
|
}
|
1998-08-19 02:19:49 +08:00
|
|
|
#endif /* !FD_SETSIZE */
|
1998-08-18 07:26:25 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
c = (Connection *) ch_calloc( 1, dtblsize * sizeof(Connection) );
|
|
|
|
|
|
|
|
for ( i = 0; i < dtblsize; i++ ) {
|
|
|
|
c[i].c_dn = NULL;
|
1999-01-19 13:10:50 +08:00
|
|
|
c[i].c_cdn = NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
c[i].c_addr = NULL;
|
|
|
|
c[i].c_domain = NULL;
|
|
|
|
c[i].c_ops = NULL;
|
1999-03-03 04:23:14 +08:00
|
|
|
lber_pvt_sb_init( &c[i].c_sb );
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &c[i].c_dnmutex );
|
|
|
|
ldap_pvt_thread_mutex_init( &c[i].c_opsmutex );
|
|
|
|
ldap_pvt_thread_mutex_init( &c[i].c_pdumutex );
|
|
|
|
ldap_pvt_thread_cond_init( &c[i].c_wcv );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (tcps = socket( AF_INET, SOCK_STREAM, 0 )) == -1 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "socket() failed errno %d (%s)", errno,
|
|
|
|
errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
|
|
|
|
"unknown", 0 );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
if ( setsockopt( tcps, SOL_SOCKET, SO_REUSEADDR, (char *) &i,
|
|
|
|
sizeof(i) ) == -1 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "setsockopt() failed errno %d (%s)",
|
|
|
|
errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
|
|
|
|
"unknown", 0 );
|
|
|
|
}
|
|
|
|
|
1999-03-17 11:56:25 +08:00
|
|
|
if ( bind( tcps, (struct sockaddr *) addr, sizeof(*addr) ) == -1 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "bind() failed errno %d (%s)\n",
|
|
|
|
errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
|
|
|
|
"unknown", 0 );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( listen( tcps, 5 ) == -1 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "listen() failed errno %d (%s)",
|
|
|
|
errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
|
|
|
|
"unknown", 0 );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
|
1999-01-05 23:40:58 +08:00
|
|
|
|
1999-01-21 23:53:54 +08:00
|
|
|
if (( slapd_pid_file != NULL ) &&
|
|
|
|
(( fp = fopen( slapd_pid_file, "w" )) != NULL )) {
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
fprintf( fp, "%d\n", (int) getpid() );
|
1998-08-09 08:43:13 +08:00
|
|
|
fclose( fp );
|
|
|
|
}
|
1999-01-21 23:53:54 +08:00
|
|
|
|
|
|
|
if (( slapd_args_file != NULL ) &&
|
|
|
|
(( fp = fopen( slapd_args_file, "w" )) != NULL )) {
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( i = 0; i < g_argc; i++ ) {
|
|
|
|
fprintf( fp, "%s ", g_argv[i] );
|
|
|
|
}
|
|
|
|
fprintf( fp, "\n" );
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( !slapd_shutdown ) {
|
|
|
|
struct sockaddr_in from;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct timeval zero;
|
|
|
|
struct timeval *tvp;
|
1999-03-09 15:15:35 +08:00
|
|
|
int len;
|
1999-03-03 04:23:14 +08:00
|
|
|
int data_ready;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-08-16 07:03:09 +08:00
|
|
|
char *client_name;
|
|
|
|
char *client_addr;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
FD_ZERO( &writefds );
|
|
|
|
FD_ZERO( &readfds );
|
|
|
|
FD_SET( tcps, &readfds );
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
zero.tv_sec = 0;
|
|
|
|
zero.tv_usec = 0;
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_CONNS,
|
|
|
|
"listening for connections on %d, activity on:",
|
|
|
|
tcps, 0, 0 );
|
1999-03-03 04:23:14 +08:00
|
|
|
|
|
|
|
data_ready = 0;
|
1998-08-09 10:28:45 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &new_conn_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( i = 0; i < dtblsize; i++ ) {
|
1999-03-16 10:59:59 +08:00
|
|
|
if ( (c[i].c_state != SLAP_C_INACTIVE)
|
|
|
|
&& (c[i].c_state != SLAP_C_CLOSING) )
|
|
|
|
{
|
|
|
|
#ifdef LDAP_DEBUG
|
|
|
|
assert(lber_pvt_sb_in_use( &c[i].c_sb ));
|
|
|
|
#endif
|
1999-03-03 04:23:14 +08:00
|
|
|
FD_SET( lber_pvt_sb_get_desc(&c[i].c_sb),
|
|
|
|
&readfds );
|
|
|
|
if (lber_pvt_sb_data_ready(&c[i].c_sb))
|
|
|
|
data_ready = 1;
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( c[i].c_writewaiter ) {
|
1999-03-03 04:23:14 +08:00
|
|
|
FD_SET( lber_pvt_sb_get_desc(&c[i].c_sb),
|
|
|
|
&writefds );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
Debug( LDAP_DEBUG_CONNS, " %dr%s", i,
|
|
|
|
c[i].c_writewaiter ? "w" : "", 0 );
|
|
|
|
}
|
|
|
|
}
|
1999-03-16 10:59:59 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_CONNS, "before select active_threads %d\n",
|
|
|
|
active_threads, 0, 0 );
|
1998-11-23 04:08:14 +08:00
|
|
|
#if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS )
|
1999-03-03 04:23:14 +08:00
|
|
|
tvp = (data_ready) ? &zero : NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
#else
|
1999-03-03 04:23:14 +08:00
|
|
|
tvp = (active_threads || data_ready) ? &zero : NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
#endif
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-08-18 07:26:25 +08:00
|
|
|
switch ( i = select( dtblsize, &readfds, &writefds, 0, tvp ) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
case -1: /* failure - try again */
|
|
|
|
Debug( LDAP_DEBUG_CONNS,
|
|
|
|
"select failed errno %d (%s)\n",
|
|
|
|
errno, errno > -1 && errno < sys_nerr ?
|
|
|
|
sys_errlist[errno] : "unknown", 0 );
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0: /* timeout - let threads run */
|
|
|
|
Debug( LDAP_DEBUG_CONNS, "select timeout - yielding\n",
|
|
|
|
0, 0, 0 );
|
1999-03-03 04:23:14 +08:00
|
|
|
if (!data_ready)
|
|
|
|
ldap_pvt_thread_yield();
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
default: /* something happened - deal with it */
|
1998-08-18 07:26:25 +08:00
|
|
|
Debug( LDAP_DEBUG_CONNS, "select activity on %d descriptors\n", i, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
; /* FALL */
|
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
time( ¤ttime );
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/* new connection */
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &new_conn_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( FD_ISSET( tcps, &readfds ) ) {
|
|
|
|
len = sizeof(from);
|
|
|
|
if ( (ns = accept( tcps, (struct sockaddr *) &from,
|
|
|
|
&len )) == -1 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"accept() failed errno %d (%s)", errno,
|
|
|
|
errno > -1 && errno < sys_nerr ?
|
|
|
|
sys_errlist[errno] : "unknown", 0 );
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
1999-03-03 05:06:42 +08:00
|
|
|
|
|
|
|
/* make sure descriptor number isn't too great */
|
|
|
|
if ( ns >= dtblsize ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"new connection on %d beyond descriptor table size %d\n",
|
|
|
|
ns, dtblsize, 0 );
|
|
|
|
close(ns);
|
|
|
|
ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_CONNS, "new connection on %d\n", ns,
|
|
|
|
0, 0 );
|
|
|
|
|
|
|
|
len = sizeof(from);
|
1998-08-16 07:03:09 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( getpeername( ns, (struct sockaddr *) &from, &len )
|
|
|
|
== 0 ) {
|
1998-08-16 07:03:09 +08:00
|
|
|
char *s;
|
|
|
|
client_addr = inet_ntoa( from.sin_addr );
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#if defined(SLAPD_RLOOKUPS) || defined(HAVE_TCPD)
|
1998-08-09 08:43:13 +08:00
|
|
|
hp = gethostbyaddr( (char *)
|
|
|
|
&(from.sin_addr.s_addr),
|
|
|
|
sizeof(from.sin_addr.s_addr), AF_INET );
|
|
|
|
|
1998-08-16 07:03:09 +08:00
|
|
|
if(hp) {
|
|
|
|
client_name = hp->h_name;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-08-16 07:03:09 +08:00
|
|
|
/* normalize the domain */
|
|
|
|
for ( s = client_name; *s; s++ ) {
|
1999-02-23 01:57:22 +08:00
|
|
|
*s = TOLOWER( (unsigned char) *s );
|
1998-08-16 07:03:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
client_name = NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-08-16 07:03:09 +08:00
|
|
|
#else
|
|
|
|
client_name = NULL;
|
|
|
|
#endif
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
1998-08-16 07:03:09 +08:00
|
|
|
client_name = NULL;;
|
|
|
|
client_addr = NULL;
|
|
|
|
}
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_TCPD
|
1999-01-07 13:47:25 +08:00
|
|
|
if(!hosts_ctl("slapd",
|
|
|
|
client_name != NULL ? client_name : STRING_UNKNOWN,
|
|
|
|
client_addr != NULL ? client_addr : STRING_UNKNOWN,
|
1998-08-16 07:03:09 +08:00
|
|
|
STRING_UNKNOWN))
|
|
|
|
{
|
|
|
|
/* DENY ACCESS */
|
1999-01-19 02:40:12 +08:00
|
|
|
Statslog( LDAP_DEBUG_ANY,
|
|
|
|
"fd=%d connection from %s (%s) denied.\n",
|
|
|
|
ns,
|
1998-08-16 07:03:09 +08:00
|
|
|
client_name == NULL ? "unknown" : client_name,
|
|
|
|
client_addr == NULL ? "unknown" : client_addr,
|
1999-01-24 09:29:23 +08:00
|
|
|
0, 0 );
|
1998-08-16 07:03:09 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
|
1998-08-16 07:03:09 +08:00
|
|
|
continue;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* HAVE_TCPD */
|
1998-08-16 07:03:09 +08:00
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &ops_mutex );
|
1999-01-19 02:40:12 +08:00
|
|
|
c[ns].c_connid = num_conns++;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &ops_mutex );
|
1999-01-19 02:40:12 +08:00
|
|
|
|
1998-08-16 07:03:09 +08:00
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
|
|
|
"conn=%d fd=%d connection from %s (%s) accepted.\n",
|
|
|
|
c[ns].c_connid, ns,
|
|
|
|
client_name == NULL ? "unknown" : client_name,
|
|
|
|
client_addr == NULL ? "unknown" : client_addr,
|
|
|
|
0 );
|
|
|
|
|
|
|
|
if ( c[ns].c_addr != NULL ) {
|
|
|
|
free( c[ns].c_addr );
|
|
|
|
}
|
1998-11-28 04:21:54 +08:00
|
|
|
c[ns].c_addr = ch_strdup( client_addr );
|
1998-08-16 07:03:09 +08:00
|
|
|
|
|
|
|
if ( c[ns].c_domain != NULL ) {
|
|
|
|
free( c[ns].c_domain );
|
|
|
|
}
|
|
|
|
|
1998-11-28 04:21:54 +08:00
|
|
|
c[ns].c_domain = ch_strdup( client_name == NULL
|
1998-08-16 07:03:09 +08:00
|
|
|
? "" : client_name );
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &c[ns].c_dnmutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( c[ns].c_dn != NULL ) {
|
|
|
|
free( c[ns].c_dn );
|
|
|
|
c[ns].c_dn = NULL;
|
|
|
|
}
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( c[ns].c_cdn != NULL ) {
|
|
|
|
free( c[ns].c_cdn );
|
|
|
|
c[ns].c_cdn = NULL;
|
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &c[ns].c_dnmutex );
|
1999-03-16 10:59:59 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
c[ns].c_starttime = currenttime;
|
1999-03-16 10:59:59 +08:00
|
|
|
c[ns].c_ops_received = 0;
|
|
|
|
c[ns].c_ops_executing = 0;
|
|
|
|
c[ns].c_ops_pending = 0;
|
|
|
|
c[ns].c_ops_completed = 0;
|
|
|
|
|
|
|
|
lber_pvt_sb_set_desc( &c[ns].c_sb, ns );
|
|
|
|
lber_pvt_sb_set_io( &c[ns].c_sb, &lber_pvt_sb_io_tcp, NULL );
|
|
|
|
|
|
|
|
if (lber_pvt_sb_set_nonblock( &c[ns].c_sb, 1)<0) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"FIONBIO ioctl on %d failed\n", ns, 0, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
c[ns].c_state = SLAP_C_ACTIVE;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_CONNS, "activity on:", 0, 0, 0 );
|
|
|
|
for ( i = 0; i < dtblsize; i++ ) {
|
|
|
|
int r, w;
|
|
|
|
|
|
|
|
r = FD_ISSET( i, &readfds );
|
|
|
|
w = FD_ISSET( i, &writefds );
|
|
|
|
if ( i != tcps && (r || w) ) {
|
|
|
|
Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
|
|
|
|
r ? "r" : "", w ? "w" : "" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
for ( i = 0; i < dtblsize; i++ ) {
|
|
|
|
if ( i == tcps || (! FD_ISSET( i, &readfds ) &&
|
|
|
|
! FD_ISSET( i, &writefds )) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( FD_ISSET( i, &writefds ) ) {
|
|
|
|
Debug( LDAP_DEBUG_CONNS,
|
|
|
|
"signaling write waiter on %d\n", i, 0, 0 );
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
active_threads++;
|
1999-01-29 13:46:12 +08:00
|
|
|
c[i].c_writewaiter = 0;
|
|
|
|
ldap_pvt_thread_cond_signal( &c[i].c_wcv );
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
if ( FD_ISSET( i, &readfds ) ||
|
|
|
|
lber_pvt_sb_data_ready( &c[i].c_sb ) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_CONNS,
|
|
|
|
"read activity on %d\n", i, 0, 0 );
|
|
|
|
|
|
|
|
connection_activity( &c[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_yield();
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-02-03 03:26:00 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"slapd shutdown: shutdown initiated.\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
close( tcps );
|
1999-01-12 02:36:40 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-03 03:26:00 +08:00
|
|
|
"slapd shutdown: waiting for %d threads to terminate\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
active_threads, 0, 0 );
|
|
|
|
while ( active_threads > 0 ) {
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_cond_wait(&active_threads_cond, &active_threads_mutex);
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
return NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-02-07 00:00:00 +08:00
|
|
|
void
|
|
|
|
slap_set_shutdown( int sig )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal %d\n", sig, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
slapd_shutdown = 1;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );
|
1999-02-07 00:00:00 +08:00
|
|
|
|
|
|
|
/* reinstall self */
|
|
|
|
(void) SIGNAL( sig, slap_set_shutdown );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-02-07 00:00:00 +08:00
|
|
|
void
|
|
|
|
slap_do_nothing( int sig )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal %d\n", sig, 0, 0 );
|
1999-02-07 00:00:00 +08:00
|
|
|
|
|
|
|
/* reinstall self */
|
|
|
|
(void) SIGNAL( sig, slap_do_nothing );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|