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;
47 unsigned long num_ops_completed;
48 ldap_pvt_thread_mutex_t num_ops_mutex;
50 unsigned long num_entries_sent;
51 unsigned long num_refs_sent;
52 unsigned long num_bytes_sent;
53 unsigned long num_pdu_sent;
54 ldap_pvt_thread_mutex_t num_sent_mutex;
56 * these mutexes must be used when calling the entry2str()
57 * routine since it returns a pointer to static data.
59 ldap_pvt_thread_mutex_t entry2str_mutex;
60 ldap_pvt_thread_mutex_t replog_mutex;
62 static const char* slap_name = NULL;
63 int slapMode = SLAP_UNDEFINED_MODE;
66 slap_init( int mode, const char *name )
72 if( slapMode != SLAP_UNDEFINED_MODE ) {
74 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
75 "init: %s init called twice (old=%d, new=%d)\n",
76 name, slapMode, mode ));
78 Debug( LDAP_DEBUG_ANY,
79 "%s init: init called twice (old=%d, new=%d)\n",
80 name, slapMode, mode );
88 switch ( slapMode & SLAP_MODE ) {
89 case SLAP_SERVER_MODE:
92 LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
93 "init: %s initiation, initiated %s.\n",
94 name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server" ));
96 Debug( LDAP_DEBUG_TRACE,
97 "%s init: initiated %s.\n", name,
98 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
105 (void) ldap_pvt_thread_initialize();
107 ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
109 ldap_pvt_thread_mutex_init( &entry2str_mutex );
110 ldap_pvt_thread_mutex_init( &replog_mutex );
111 ldap_pvt_thread_mutex_init( &num_ops_mutex );
112 ldap_pvt_thread_mutex_init( &num_sent_mutex );
114 ldap_pvt_thread_mutex_init( &gmtime_mutex );
115 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
116 ldap_pvt_thread_mutex_init( &passwd_mutex );
119 rc = slap_sasl_init();
122 rc = backend_init( );
128 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
129 "init: %s init, undefined mode (%d).\n", name, mode ));
131 Debug( LDAP_DEBUG_ANY,
132 "%s init: undefined mode (%d).\n", name, mode, 0 );
142 int slap_startup( Backend *be )
147 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
148 "slap_startup: %s started\n", slap_name ));
150 Debug( LDAP_DEBUG_TRACE,
151 "%s startup: initiated.\n",
156 rc = backend_startup( be );
161 int slap_shutdown( Backend *be )
166 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
167 "slap_shutdown: %s shutdown initiated.\n", slap_name));
169 Debug( LDAP_DEBUG_TRACE,
170 "%s shutdown: initiated\n",
177 /* let backends do whatever cleanup they need to do */
178 rc = backend_shutdown( be );
183 int slap_destroy(void)
188 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
189 "slap_destroy: %s freeing system resources.\n",
192 Debug( LDAP_DEBUG_TRACE,
193 "%s shutdown: freeing system resources.\n",
198 rc = backend_destroy();
202 ldap_pvt_thread_destroy();
204 /* should destory the above mutex */