]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/daemon.c
If dn2id returns ID but id2entry returns NULL, log it.
[openldap] / servers / slapd / daemon.c
index 5a33a31e8580ef166d3f809c9fb1a79d8752148b..a7a7335de6955dda007ccd4f8c846d0322bc8d71 100644 (file)
@@ -40,11 +40,9 @@ static volatile sig_atomic_t slapd_shutdown = 0;
 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(
@@ -62,13 +60,6 @@ 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
@@ -87,6 +78,7 @@ slapd_daemon(
 
        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;
@@ -149,30 +141,20 @@ slapd_daemon(
 
        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;
@@ -260,14 +242,9 @@ slapd_daemon(
                                    "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 )
@@ -307,9 +284,9 @@ slapd_daemon(
                                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 );
@@ -320,6 +297,11 @@ slapd_daemon(
                        }
 #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,
@@ -344,6 +326,10 @@ slapd_daemon(
                                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;
@@ -393,14 +379,13 @@ slapd_daemon(
        }
 
        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 );