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>
23 * read-only global variables or variables only written by the listener
24 * thread (after they are initialized) - no need to protect them with a mutex.
29 int ldap_syslog = LDAP_DEBUG_STATS;
35 int ldap_syslog_level = LOG_DEBUG;
38 BerVarray default_referral = NULL;
40 struct berval AllUser = BER_BVC( LDAP_ALL_USER_ATTRIBUTES );
41 struct berval AllOper = BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES );
42 struct berval NoAttrs = BER_BVC( LDAP_NO_ATTRS );
45 * global variables that need mutex protection
47 ldap_pvt_thread_pool_t connection_pool;
48 int connection_pool_max = SLAP_MAX_WORKER_THREADS;
49 ldap_pvt_thread_mutex_t gmtime_mutex;
50 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
51 ldap_pvt_thread_mutex_t passwd_mutex;
54 unsigned long num_ops_initiated = 0;
55 unsigned long num_ops_completed = 0;
57 unsigned long num_ops_initiated_[SLAP_OP_LAST];
58 unsigned long num_ops_completed_[SLAP_OP_LAST];
59 #endif /* SLAPD_MONITOR */
60 ldap_pvt_thread_mutex_t num_ops_mutex;
62 unsigned long num_entries_sent;
63 unsigned long num_refs_sent;
64 unsigned long num_bytes_sent;
65 unsigned long num_pdu_sent;
66 ldap_pvt_thread_mutex_t num_sent_mutex;
68 * these mutexes must be used when calling the entry2str()
69 * routine since it returns a pointer to static data.
71 ldap_pvt_thread_mutex_t entry2str_mutex;
72 ldap_pvt_thread_mutex_t replog_mutex;
74 static const char* slap_name = NULL;
75 int slapMode = SLAP_UNDEFINED_MODE;
78 slap_init( int mode, const char *name )
84 if( slapMode != SLAP_UNDEFINED_MODE ) {
86 LDAP_LOG( OPERATION, CRIT,
87 "init: %s init called twice (old=%d, new=%d)\n",
88 name, slapMode, mode );
90 Debug( LDAP_DEBUG_ANY,
91 "%s init: init called twice (old=%d, new=%d)\n",
92 name, slapMode, mode );
100 switch ( slapMode & SLAP_MODE ) {
101 case SLAP_SERVER_MODE:
104 LDAP_LOG( OPERATION, DETAIL1,
105 "init: %s initiation, initiated %s.\n",
106 name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ?
107 "tool" : "server", 0 );
109 Debug( LDAP_DEBUG_TRACE,
110 "%s init: initiated %s.\n", name,
111 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
118 (void) ldap_pvt_thread_initialize();
120 ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
122 ldap_pvt_thread_mutex_init( &entry2str_mutex );
123 ldap_pvt_thread_mutex_init( &replog_mutex );
124 ldap_pvt_thread_mutex_init( &num_ops_mutex );
125 ldap_pvt_thread_mutex_init( &num_sent_mutex );
130 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
131 num_ops_initiated_[ i ] = 0;
132 num_ops_completed_[ i ] = 0;
137 ldap_pvt_thread_mutex_init( &gmtime_mutex );
138 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
139 ldap_pvt_thread_mutex_init( &passwd_mutex );
142 rc = slap_sasl_init();
145 rc = backend_init( );
152 LDAP_LOG( OPERATION, ERR,
153 "init: %s init, undefined mode (%d).\n", name, mode, 0 );
155 Debug( LDAP_DEBUG_ANY,
156 "%s init: undefined mode (%d).\n", name, mode, 0 );
166 int slap_startup( Backend *be )
171 LDAP_LOG( OPERATION, CRIT, "slap_startup: %s started\n", slap_name, 0, 0 );
173 Debug( LDAP_DEBUG_TRACE,
174 "%s startup: initiated.\n",
179 rc = backend_startup( be );
183 Slapi_PBlock *pb = slapi_pblock_new();
185 if ( doPluginFNs( NULL, SLAPI_PLUGIN_START_FN, pb ) < 0 ) {
188 slapi_pblock_destroy( pb );
190 #endif /* LDAP_SLAPI */
195 int slap_shutdown( Backend *be )
203 LDAP_LOG( OPERATION, CRIT,
204 "slap_shutdown: %s shutdown initiated.\n", slap_name, 0, 0);
206 Debug( LDAP_DEBUG_TRACE,
207 "%s shutdown: initiated\n",
214 /* let backends do whatever cleanup they need to do */
215 rc = backend_shutdown( be );
218 pb = slapi_pblock_new( );
219 (void) doPluginFNs( NULL, SLAPI_PLUGIN_CLOSE_FN, pb );
220 slapi_pblock_destroy( pb );
221 #endif /* LDAP_SLAPI */
226 int slap_destroy(void)
231 LDAP_LOG( OPERATION, INFO,
232 "slap_destroy: %s freeing system resources.\n", slap_name, 0, 0);
234 Debug( LDAP_DEBUG_TRACE,
235 "%s shutdown: freeing system resources.\n",
240 rc = backend_destroy();
244 ldap_pvt_thread_destroy();
246 /* should destory the above mutex */