]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
Cleanup slapd search op deallocation.
[openldap] / servers / slapd / main.c
index 733fb10e7f061a65e6e41f651e7d9ace3cc9ece3..30dc6cf9afcf2142356ee94c491d6500d98460e8 100644 (file)
  * read-only global variables or variables only written by the listener
  * thread (after they are initialized) - no need to protect them with a mutex.
  */
-int            ldap_debug = 0;
+int            slap_debug = 0;
+
 #ifdef LDAP_DEBUG
 int            ldap_syslog = LDAP_DEBUG_STATS;
 #else
 int            ldap_syslog;
 #endif
+
 int            ldap_syslog_level = LOG_DEBUG;
 int            udp;
-int            slapd_shutdown;
 char           *default_referral;
 char           *configfile;
 time_t         starttime;
@@ -36,9 +37,13 @@ char         **g_argv;
  */
 time_t         currenttime;
 pthread_mutex_t        currenttime_mutex;
+pthread_mutex_t        strtok_mutex;
 int            active_threads;
 pthread_mutex_t        active_threads_mutex;
 pthread_mutex_t        new_conn_mutex;
+#ifdef SLAPD_CRYPT
+pthread_mutex_t crypt_mutex;
+#endif
 long           ops_initiated;
 long           ops_completed;
 int            num_conns;
@@ -53,10 +58,58 @@ pthread_mutex_t     num_sent_mutex;
 pthread_mutex_t        entry2str_mutex;
 pthread_mutex_t        replog_mutex;
 
+/*
+ * when more than one slapd is running on one machine, each one might have
+ * it's own LOCAL for syslogging and must have its own pid/args files
+ */
+
+#ifdef LOG_LOCAL4
+
+#define DEFAULT_SYSLOG_USER  LOG_LOCAL4
+
+typedef struct _str2intDispatch {
+
+        char    *stringVal;
+        int      abbr;
+        int      intVal;
+
+} STRDISP, *STRDISP_P;
+
+
+/* table to compute syslog-options to integer */
+static STRDISP  syslog_types[] = {
+
+    { "LOCAL0",         6, LOG_LOCAL0 },
+    { "LOCAL1",         6, LOG_LOCAL1 },
+    { "LOCAL2",         6, LOG_LOCAL2 },
+    { "LOCAL3",         6, LOG_LOCAL3 },
+    { "LOCAL4",         6, LOG_LOCAL4 },
+    { "LOCAL5",         6, LOG_LOCAL5 },
+    { "LOCAL6",         6, LOG_LOCAL6 },
+    { "LOCAL7",         6, LOG_LOCAL7 },
+    NULL
+
+};
+
+static int   cnvt_str2int();
+
+#endif  /* LOG_LOCAL4 */
+
+/*
+ * the server's name must be accessible from the daemon module,
+ * to construct the pid/args file names
+ */
+char  *serverName = NULL;
+
+
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name );
+       fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name );
+#ifdef LOG_LOCAL4
+    fprintf( stderr, " [-l sysloguser]" );
+#endif
+    fprintf( stderr, "\n" );
 }
 
 int
@@ -65,10 +118,11 @@ main( int argc, char **argv )
        int             i;
        int             inetd = 0;
        int             port;
-       char            *myname;
        Backend         *be = NULL;
        FILE            *fp = NULL;
-       extern char     *optarg;
+#ifdef LOG_LOCAL4
+    int     syslogUser = DEFAULT_SYSLOG_USER;
+#endif
 
        configfile = SLAPD_DEFAULT_CONFIGFILE;
        port = LDAP_PORT;
@@ -109,8 +163,7 @@ main( int argc, char **argv )
                                    LDAP_DEBUG_ANY );
                                exit( 0 );
                        } else {
-                               ldap_debug |= atoi( optarg );
-                               lber_debug = (ldap_debug & LDAP_DEBUG_BER);
+                               slap_debug |= atoi( optarg );
                        }
                        break;
 #else
@@ -121,7 +174,7 @@ main( int argc, char **argv )
 #endif
 
                case 'f':       /* read config file */
-                       configfile = strdup( optarg );
+                       configfile = ch_strdup( optarg );
                        break;
 
                case 'i':       /* run from inetd */
@@ -136,6 +189,15 @@ main( int argc, char **argv )
                        ldap_syslog = atoi( optarg );
                        break;
 
+#ifdef LOG_LOCAL4
+
+               case 'l':       /* set syslog local user */
+                       syslogUser = cnvt_str2int( optarg, syslog_types,
+                                           DEFAULT_SYSLOG_USER );
+                       break;
+
+#endif
+
                case 'u':       /* do udp */
                        udp = 1;
                        break;
@@ -146,12 +208,16 @@ main( int argc, char **argv )
                }
        }
 
+       lber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
+       ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
+       ldif_debug = slap_debug;
+
        Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );
 
-       if ( (myname = strrchr( argv[0], '/' )) == NULL ) {
-               myname = strdup( argv[0] );
+       if ( (serverName = strrchr( argv[0], '/' )) == NULL ) {
+               serverName = ch_strdup( argv[0] );
        } else {
-               myname = strdup( myname + 1 );
+               serverName = ch_strdup( serverName + 1 );
        }
 
        if ( ! inetd ) {
@@ -163,47 +229,36 @@ main( int argc, char **argv )
                lutil_detach( 0, 0 );
 #endif
        }
+
 #ifdef LOG_LOCAL4
-       openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
+       openlog( serverName, OPENLOG_OPTIONS, syslogUser );
 #else
-       openlog( myname, OPENLOG_OPTIONS );
+       openlog( serverName, OPENLOG_OPTIONS );
 #endif
 
        init();
        read_config( configfile, &be, fp );
 
        if ( ! inetd ) {
-               pthread_attr_t  attr;
                int             status;
 
                time( &starttime );
-               pthread_attr_init( &attr );
-               pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
-
-#if !defined(HAVE_PTHREADS_D4)
-               /* POSIX_THREADS or compatible
-                * This is a draft 10 or standard pthreads implementation
-                */
-               if ( pthread_create( &listener_tid, &attr, slapd_daemon,
-                   (void *) port ) != 0 ) {
-                       Debug( LDAP_DEBUG_ANY,
-                           "listener pthread_create failed\n", 0, 0, 0 );
-                       exit( 1 );
-               }
-#else  /* draft4 */
-               /*
-                * This is a draft 4 or earlier pthreads implementation
-                */
-               if ( pthread_create( &listener_tid, attr, slapd_daemon,
+
+               if ( pthread_create( &listener_tid, NULL, slapd_daemon,
                    (void *) port ) != 0 ) {
                        Debug( LDAP_DEBUG_ANY,
                            "listener pthread_create failed\n", 0, 0, 0 );
                        exit( 1 );
                }
-#endif /* !draft4 */
-               pthread_attr_destroy( &attr );
+
+#ifdef HAVE_PHREADS_FINAL
+               pthread_join( listener_tid, (void *) NULL );
+#else
                pthread_join( listener_tid, (void *) &status );
-               pthread_exit( 0 );
+#endif
+
+               return 0;
+
        } else {
                Connection              c;
                Operation               *o;
@@ -244,7 +299,7 @@ main( int argc, char **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 );
@@ -263,6 +318,7 @@ main( int argc, char **argv )
                                /* log and send error */
                                Debug( LDAP_DEBUG_ANY,
                                   "ber_get_int returns 0x%lx\n", tag, 0, 0 );
+                               ber_free( &ber, 1 );
                                return 1;
                        }
 
@@ -284,3 +340,37 @@ main( int argc, char **argv )
        }
        return 1;
 }
+
+
+#ifdef LOG_LOCAL4
+
+/*
+ *  Convert a string to an integer by means of a dispatcher table
+ *  if the string is not in the table return the default
+ */
+
+static int
+cnvt_str2int (stringVal, dispatcher, defaultVal)
+char      *stringVal;
+STRDISP_P  dispatcher;
+int        defaultVal;
+{
+    int        retVal = defaultVal;
+    STRDISP_P  disp;
+
+    for (disp = dispatcher; disp->stringVal; disp++) {
+
+        if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) {
+
+            retVal = disp->intVal;
+            break;
+
+        }
+    }
+
+    return (retVal);
+
+} /* cnvt_str2int */
+
+#endif  /* LOG_LOCAL4 */
+