]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
Apply ITS#12 fix from devel.
[openldap] / servers / slapd / main.c
index e93777db73085f6e6f8967771ebeed8912b3e81b..af2c86c8ef5e6cfad3ddc4230e964d501243ce80 100644 (file)
@@ -5,14 +5,11 @@
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/time.h>
+#include <ac/unistd.h>
 
-#include "slap.h"
 #include "ldapconfig.h"
-
-extern void    slapd_daemon();
-extern int     lber_debug;
-
-extern char Versionstr[];
+#include "slap.h"
+#include "lutil.h"                     /* Get lutil_detach() */
 
 
 /*
@@ -56,16 +53,14 @@ pthread_mutex_t     num_sent_mutex;
 pthread_mutex_t        entry2str_mutex;
 pthread_mutex_t        replog_mutex;
 
-static
-usage( name )
-    char       *name;
+static void
+usage( char *name )
 {
        fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name );
 }
 
-main( argc, argv )
-    int                argc;
-    char       **argv;
+int
+main( int argc, char **argv )
 {
        int             i;
        int             inetd = 0;
@@ -73,7 +68,6 @@ main( argc, argv )
        char            *myname;
        Backend         *be = NULL;
        FILE            *fp = NULL;
-       extern char     *optarg;
 
        configfile = SLAPD_DEFAULT_CONFIGFILE;
        port = LDAP_PORT;
@@ -126,7 +120,7 @@ main( argc, argv )
 #endif
 
                case 'f':       /* read config file */
-                       configfile = strdup( optarg );
+                       configfile = ch_strdup( optarg );
                        break;
 
                case 'i':       /* run from inetd */
@@ -154,9 +148,9 @@ main( argc, argv )
        Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );
 
        if ( (myname = strrchr( argv[0], '/' )) == NULL ) {
-               myname = strdup( argv[0] );
+               myname = ch_strdup( argv[0] );
        } else {
-               myname = strdup( myname + 1 );
+               myname = ch_strdup( myname + 1 );
        }
 
        if ( ! inetd ) {
@@ -183,9 +177,12 @@ main( argc, argv )
 
                time( &starttime );
                pthread_attr_init( &attr );
+#ifdef DETACH_LISTENER_THREAD
+               /* we should detach it if we're going to join with it */
                pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
+#endif
 
-#if !defined(HAVE_PTHREADS_D4) && !defined(HAVE_DCE)
+#if !defined(HAVE_PTHREADS_D4)
                /* POSIX_THREADS or compatible
                 * This is a draft 10 or standard pthreads implementation
                 */
@@ -207,7 +204,11 @@ main( argc, argv )
                }
 #endif /* !draft4 */
                pthread_attr_destroy( &attr );
+#ifdef HAVE_PHREADS_FINAL
+               pthread_join( listener_tid, (void *) NULL );
+#else
                pthread_join( listener_tid, (void *) &status );
+#endif
                pthread_exit( 0 );
        } else {
                Connection              c;
@@ -249,7 +250,7 @@ main( argc, argv )
                            inet_ntoa( from.sin_addr ), 0 );
 
                        c.c_addr = inet_ntoa( from.sin_addr );
-                       c.c_domain = strdup( hp == NULL ? "" : hp->h_name );
+                       c.c_domain = ch_strdup( hp == NULL ? "" : hp->h_name );
                } else {
                        Debug( LDAP_DEBUG_ARGS, "connection from unknown\n",
                            0, 0, 0 );
@@ -266,19 +267,19 @@ main( argc, argv )
                            != LDAP_TAG_MSGID ) {
                                /* log and send error */
                                Debug( LDAP_DEBUG_ANY,
-                                   "ber_get_int returns 0x%x\n", tag, 0, 0 );
-                               return;
+                                  "ber_get_int returns 0x%lx\n", tag, 0, 0 );
+                               return 1;
                        }
 
                        if ( (tag = ber_peek_tag( &ber, &len ))
                            == LBER_ERROR ) {
                                /* log, close and send error */
                                Debug( LDAP_DEBUG_ANY,
-                                   "ber_peek_tag returns 0x%x\n", tag, 0, 0 );
+                                  "ber_peek_tag returns 0x%lx\n", tag, 0, 0 );
                                ber_free( &ber, 1 );
                                close( c.c_sb.sb_sd );
                                c.c_sb.sb_sd = -1;
-                               return;
+                               return 1;
                        }
 
                        connection_activity( &c );
@@ -286,4 +287,5 @@ main( argc, argv )
                        ber_free( &ber, 1 );
                }
        }
+       return 1;
 }