1 /* init.c - initialize various things */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
19 * read-only global variables or variables only written by the listener
20 * thread (after they are initialized) - no need to protect them with a mutex.
25 int ldap_syslog = LDAP_DEBUG_STATS;
31 int ldap_syslog_level = LOG_DEBUG;
34 BerVarray default_referral = NULL;
37 * global variables that need mutex protection
39 ldap_pvt_thread_pool_t connection_pool;
40 int connection_pool_max = SLAP_MAX_WORKER_THREADS;
41 ldap_pvt_thread_mutex_t gmtime_mutex;
42 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
43 ldap_pvt_thread_mutex_t passwd_mutex;
46 unsigned long num_ops_initiated = 0;
47 unsigned long num_ops_completed = 0;
49 unsigned long num_ops_initiated_[SLAP_OP_LAST];
50 unsigned long num_ops_completed_[SLAP_OP_LAST];
51 #endif /* SLAPD_MONITOR */
52 ldap_pvt_thread_mutex_t num_ops_mutex;
54 unsigned long num_entries_sent;
55 unsigned long num_refs_sent;
56 unsigned long num_bytes_sent;
57 unsigned long num_pdu_sent;
58 ldap_pvt_thread_mutex_t num_sent_mutex;
60 * these mutexes must be used when calling the entry2str()
61 * routine since it returns a pointer to static data.
63 ldap_pvt_thread_mutex_t entry2str_mutex;
64 ldap_pvt_thread_mutex_t replog_mutex;
66 static const char* slap_name = NULL;
67 int slapMode = SLAP_UNDEFINED_MODE;
70 slap_init( int mode, const char *name )
76 if( slapMode != SLAP_UNDEFINED_MODE ) {
78 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
79 "init: %s init called twice (old=%d, new=%d)\n",
80 name, slapMode, mode ));
82 Debug( LDAP_DEBUG_ANY,
83 "%s init: init called twice (old=%d, new=%d)\n",
84 name, slapMode, mode );
92 switch ( slapMode & SLAP_MODE ) {
93 case SLAP_SERVER_MODE:
96 LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
97 "init: %s initiation, initiated %s.\n",
98 name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server" ));
100 Debug( LDAP_DEBUG_TRACE,
101 "%s init: initiated %s.\n", name,
102 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
109 (void) ldap_pvt_thread_initialize();
111 ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
113 ldap_pvt_thread_mutex_init( &entry2str_mutex );
114 ldap_pvt_thread_mutex_init( &replog_mutex );
115 ldap_pvt_thread_mutex_init( &num_ops_mutex );
116 ldap_pvt_thread_mutex_init( &num_sent_mutex );
121 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
122 num_ops_initiated_[ i ] = 0;
123 num_ops_completed_[ i ] = 0;
128 ldap_pvt_thread_mutex_init( &gmtime_mutex );
129 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
130 ldap_pvt_thread_mutex_init( &passwd_mutex );
133 rc = slap_sasl_init();
136 rc = backend_init( );
142 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
143 "init: %s init, undefined mode (%d).\n", name, mode ));
145 Debug( LDAP_DEBUG_ANY,
146 "%s init: undefined mode (%d).\n", name, mode, 0 );
156 int slap_startup( Backend *be )
161 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
162 "slap_startup: %s started\n", slap_name ));
164 Debug( LDAP_DEBUG_TRACE,
165 "%s startup: initiated.\n",
170 rc = backend_startup( be );
175 int slap_shutdown( Backend *be )
180 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
181 "slap_shutdown: %s shutdown initiated.\n", slap_name));
183 Debug( LDAP_DEBUG_TRACE,
184 "%s shutdown: initiated\n",
191 /* let backends do whatever cleanup they need to do */
192 rc = backend_shutdown( be );
197 int slap_destroy(void)
202 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
203 "slap_destroy: %s freeing system resources.\n",
206 Debug( LDAP_DEBUG_TRACE,
207 "%s shutdown: freeing system resources.\n",
212 rc = backend_destroy();
216 ldap_pvt_thread_destroy();
218 /* should destory the above mutex */