]> 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 d14f37eda42a26c3cdd3dfdc9c5ea16deaf991a9..a7a7335de6955dda007ccd4f8c846d0322bc8d71 100644 (file)
@@ -36,9 +36,14 @@ int deny_severity = LOG_NOTICE;
 int            dtblsize;
 Connection     *c;
 
+static volatile sig_atomic_t slapd_shutdown = 0;
 static void    set_shutdown(int sig);
 static void    do_nothing  (int sig);
 
+/* a link to the slapd.conf configuration parameters */
+extern char *slapd_pid_file;
+extern char *slapd_args_file;
+
 void *
 slapd_daemon(
     void *port
@@ -73,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;
@@ -134,21 +140,21 @@ slapd_daemon(
        (void) SIGNAL( SIGHUP, set_shutdown );
 
        Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
-#ifdef SLAPD_PIDFILE
-       if ( (fp = fopen( SLAPD_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_ARGSFILE
-       if ( (fp = fopen( SLAPD_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
 
        while ( !slapd_shutdown ) {
                struct sockaddr_in      from;
@@ -236,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 )
@@ -277,13 +278,15 @@ slapd_daemon(
                        }
 
 #ifdef HAVE_TCPD
-                       if(!hosts_ctl("slapd", client_name, client_addr,
+                       if(!hosts_ctl("slapd",
+                               client_name != NULL ? client_name : STRING_UNKNOWN,
+                               client_addr != NULL ? client_addr : STRING_UNKNOWN,
                                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 );
@@ -294,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,
@@ -318,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;
@@ -367,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 );