1 /* init.c - initialize various things */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
20 * read-only global variables or variables only written by the listener
21 * thread (after they are initialized) - no need to protect them with a mutex.
26 int ldap_syslog = LDAP_DEBUG_STATS;
32 int ldap_syslog_level = LOG_DEBUG;
35 BerVarray default_referral = NULL;
37 struct berval AllUser = BER_BVC( LDAP_ALL_USER_ATTRIBUTES );
38 struct berval AllOper = BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES );
39 struct berval NoAttrs = BER_BVC( LDAP_NO_ATTRS );
42 * global variables that need mutex protection
44 ldap_pvt_thread_pool_t connection_pool;
45 int connection_pool_max = SLAP_MAX_WORKER_THREADS;
46 ldap_pvt_thread_mutex_t gmtime_mutex;
47 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
48 ldap_pvt_thread_mutex_t passwd_mutex;
51 unsigned long num_ops_initiated = 0;
52 unsigned long num_ops_completed = 0;
54 unsigned long num_ops_initiated_[SLAP_OP_LAST];
55 unsigned long num_ops_completed_[SLAP_OP_LAST];
56 #endif /* SLAPD_MONITOR */
57 ldap_pvt_thread_mutex_t num_ops_mutex;
59 unsigned long num_entries_sent;
60 unsigned long num_refs_sent;
61 unsigned long num_bytes_sent;
62 unsigned long num_pdu_sent;
63 ldap_pvt_thread_mutex_t num_sent_mutex;
65 * these mutexes must be used when calling the entry2str()
66 * routine since it returns a pointer to static data.
68 ldap_pvt_thread_mutex_t entry2str_mutex;
69 ldap_pvt_thread_mutex_t replog_mutex;
71 static const char* slap_name = NULL;
72 int slapMode = SLAP_UNDEFINED_MODE;
75 slap_init( int mode, const char *name )
81 if( slapMode != SLAP_UNDEFINED_MODE ) {
83 LDAP_LOG( OPERATION, CRIT,
84 "init: %s init called twice (old=%d, new=%d)\n",
85 name, slapMode, mode );
87 Debug( LDAP_DEBUG_ANY,
88 "%s init: init called twice (old=%d, new=%d)\n",
89 name, slapMode, mode );
97 switch ( slapMode & SLAP_MODE ) {
98 case SLAP_SERVER_MODE:
101 LDAP_LOG( OPERATION, DETAIL1,
102 "init: %s initiation, initiated %s.\n",
103 name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ?
104 "tool" : "server", 0 );
106 Debug( LDAP_DEBUG_TRACE,
107 "%s init: initiated %s.\n", name,
108 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
115 (void) ldap_pvt_thread_initialize();
117 ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
119 ldap_pvt_thread_mutex_init( &entry2str_mutex );
120 ldap_pvt_thread_mutex_init( &replog_mutex );
121 ldap_pvt_thread_mutex_init( &num_ops_mutex );
122 ldap_pvt_thread_mutex_init( &num_sent_mutex );
127 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
128 num_ops_initiated_[ i ] = 0;
129 num_ops_completed_[ i ] = 0;
134 ldap_pvt_thread_mutex_init( &gmtime_mutex );
135 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
136 ldap_pvt_thread_mutex_init( &passwd_mutex );
139 rc = slap_sasl_init();
142 rc = backend_init( );
148 LDAP_LOG( OPERATION, ERR,
149 "init: %s init, undefined mode (%d).\n", name, mode, 0 );
151 Debug( LDAP_DEBUG_ANY,
152 "%s init: undefined mode (%d).\n", name, mode, 0 );
162 int slap_startup( Backend *be )
167 LDAP_LOG( OPERATION, CRIT, "slap_startup: %s started\n", slap_name, 0, 0 );
169 Debug( LDAP_DEBUG_TRACE,
170 "%s startup: initiated.\n",
175 rc = backend_startup( be );
180 int slap_shutdown( Backend *be )
185 LDAP_LOG( OPERATION, CRIT,
186 "slap_shutdown: %s shutdown initiated.\n", slap_name, 0, 0);
188 Debug( LDAP_DEBUG_TRACE,
189 "%s shutdown: initiated\n",
196 /* let backends do whatever cleanup they need to do */
197 rc = backend_shutdown( be );
202 int slap_destroy(void)
207 LDAP_LOG( OPERATION, INFO,
208 "slap_destroy: %s freeing system resources.\n", slap_name, 0, 0);
210 Debug( LDAP_DEBUG_TRACE,
211 "%s shutdown: freeing system resources.\n",
216 rc = backend_destroy();
220 ldap_pvt_thread_destroy();
222 /* should destory the above mutex */