static void set_shutdown(int sig);
static void do_nothing (int sig);
-/* we need the server's name for constructing the pid/args file names */
-#if defined( SLAPD_PIDEXT ) || defined( SLAPD_ARGSEXT )
-extern char *serverName;
-#define DEFAULT_SERVERNAME "slapd"
-#endif
+/* a link to the slapd.conf configuration parameters */
+extern char *slapd_pid_file;
+extern char *slapd_args_file;
void *
slapd_daemon(
FILE *fp;
int on = 1;
-#ifdef SLAPD_PIDEXT
- char pidFile[BUFSIZ];
-#endif
-#ifdef SLAPD_ARGSEXT
- char argsFile[BUFSIZ];
-#endif
-
#ifdef HAVE_SYSCONF
dtblsize = sysconf( _SC_OPEN_MAX );
#elif HAVE_GETDTABLESIZE
for ( i = 0; i < dtblsize; i++ ) {
c[i].c_dn = NULL;
+ c[i].c_cdn = NULL;
c[i].c_addr = NULL;
c[i].c_domain = NULL;
c[i].c_ops = NULL;
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
-#if defined( SLAPD_PIDEXT ) || defined( SLAPD_ARGSEXT )
- if ( !serverName ) serverName = DEFAULT_SERVERNAME;
-
-#ifdef SLAPD_PIDEXT
- sprintf( pidFile, "%s%s%s%s", DEFAULT_RUNDIR, DEFAULT_DIRSEP,
- serverName, SLAPD_PIDEXT );
- if ( (fp = fopen( pidFile, "w" )) != NULL ) {
+ if (( slapd_pid_file != NULL ) &&
+ (( fp = fopen( slapd_pid_file, "w" )) != NULL )) {
fprintf( fp, "%d\n", (int) getpid() );
fclose( fp );
}
-#endif
-#ifdef SLAPD_ARGSEXT
- sprintf( argsFile, "%s%s%s%s", DEFAULT_RUNDIR, DEFAULT_DIRSEP,
- serverName, SLAPD_ARGSEXT );
- if ( (fp = fopen( argsFile, "w" )) != NULL ) {
+
+ if (( slapd_args_file != NULL ) &&
+ (( fp = fopen( slapd_args_file, "w" )) != NULL )) {
for ( i = 0; i < g_argc; i++ ) {
fprintf( fp, "%s ", g_argv[i] );
}
fprintf( fp, "\n" );
fclose( fp );
}
-#endif
-#endif
-
while ( !slapd_shutdown ) {
struct sockaddr_in from;
"FIONBIO ioctl on %d failed\n", ns, 0, 0 );
}
- c[ns].c_sb.sb_sd = ns;
Debug( LDAP_DEBUG_CONNS, "new connection on %d\n", ns,
0, 0 );
- pthread_mutex_lock( &ops_mutex );
- c[ns].c_connid = num_conns++;
- pthread_mutex_unlock( &ops_mutex );
-
len = sizeof(from);
if ( getpeername( ns, (struct sockaddr *) &from, &len )
STRING_UNKNOWN))
{
/* DENY ACCESS */
- Statslog( LDAP_DEBUG_STATS,
- "conn=%d fd=%d connection from %s (%s) denied.\n",
- c[ns].c_connid, ns,
+ Statslog( LDAP_DEBUG_ANY,
+ "fd=%d connection from %s (%s) denied.\n",
+ ns,
client_name == NULL ? "unknown" : client_name,
client_addr == NULL ? "unknown" : client_addr,
0 );
}
#endif /* HAVE_TCPD */
+ c[ns].c_sb.sb_sd = ns;
+ pthread_mutex_lock( &ops_mutex );
+ c[ns].c_connid = num_conns++;
+ pthread_mutex_unlock( &ops_mutex );
+
Statslog( LDAP_DEBUG_STATS,
"conn=%d fd=%d connection from %s (%s) accepted.\n",
c[ns].c_connid, ns,
free( c[ns].c_dn );
c[ns].c_dn = NULL;
}
+ if ( c[ns].c_cdn != NULL ) {
+ free( c[ns].c_cdn );
+ c[ns].c_cdn = NULL;
+ }
pthread_mutex_unlock( &c[ns].c_dnmutex );
c[ns].c_starttime = currenttime;
c[ns].c_opsinitiated = 0;
}
close( tcps );
+
pthread_mutex_lock( &active_threads_mutex );
Debug( LDAP_DEBUG_ANY,
"slapd shutting down - waiting for %d threads to terminate\n",
active_threads, 0, 0 );
while ( active_threads > 0 ) {
- pthread_mutex_unlock( &active_threads_mutex );
- pthread_yield();
- pthread_mutex_lock( &active_threads_mutex );
+ pthread_cond_wait(&active_threads_cond, &active_threads_mutex);
}
pthread_mutex_unlock( &active_threads_mutex );