1 /* init.c - initialize various things */
4 * Copyright 1998-2000 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 struct berval **default_referral = NULL;
39 * global variables that need mutex protection
41 ldap_pvt_thread_pool_t connection_pool;
42 int connection_pool_max = SLAP_MAX_WORKER_THREADS;
43 ldap_pvt_thread_mutex_t gmtime_mutex;
44 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
45 ldap_pvt_thread_mutex_t passwd_mutex;
49 long num_ops_initiated;
50 long num_ops_completed;
51 ldap_pvt_thread_mutex_t num_ops_mutex;
53 long num_entries_sent;
57 ldap_pvt_thread_mutex_t num_sent_mutex;
59 * these mutexes must be used when calling the entry2str()
60 * routine since it returns a pointer to static data.
62 ldap_pvt_thread_mutex_t entry2str_mutex;
63 ldap_pvt_thread_mutex_t replog_mutex;
65 static const char* slap_name = NULL;
66 int slapMode = SLAP_UNDEFINED_MODE;
69 slap_init( int mode, const char *name )
75 if( slapMode != SLAP_UNDEFINED_MODE ) {
77 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
78 "init: %s init called twice (old=%d, new=%d)\n",
79 name, slapMode, mode ));
81 Debug( LDAP_DEBUG_ANY,
82 "%s init: init called twice (old=%d, new=%d)\n",
83 name, slapMode, mode );
91 switch ( slapMode & SLAP_MODE ) {
92 case SLAP_SERVER_MODE:
95 LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
96 "init: %s initiation, initiated %s.\n",
97 name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server" ));
99 Debug( LDAP_DEBUG_TRACE,
100 "%s init: initiated %s.\n", name,
101 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
108 (void) ldap_pvt_thread_initialize();
110 ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
112 ldap_pvt_thread_mutex_init( &entry2str_mutex );
113 ldap_pvt_thread_mutex_init( &replog_mutex );
114 ldap_pvt_thread_mutex_init( &num_ops_mutex );
115 ldap_pvt_thread_mutex_init( &num_sent_mutex );
117 ldap_pvt_thread_mutex_init( &gmtime_mutex );
118 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
119 ldap_pvt_thread_mutex_init( &passwd_mutex );
122 rc = slap_sasl_init();
125 rc = backend_init( );
131 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
132 "init: %s init, undefined mode (%d).\n", name, mode ));
134 Debug( LDAP_DEBUG_ANY,
135 "%s init: undefined mode (%d).\n", name, mode, 0 );
145 int slap_startup( Backend *be )
150 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
151 "slap_startup: %s started\n", slap_name ));
153 Debug( LDAP_DEBUG_TRACE,
154 "%s startup: initiated.\n",
159 rc = backend_startup( be );
164 int slap_shutdown( Backend *be )
169 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
170 "slap_shutdown: %s shutdown initiated.\n", slap_name));
172 Debug( LDAP_DEBUG_TRACE,
173 "%s shutdown: initiated\n",
180 /* let backends do whatever cleanup they need to do */
181 rc = backend_shutdown( be );
186 int slap_destroy(void)
191 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
192 "slap_destroy: %s freeing system resources.\n",
195 Debug( LDAP_DEBUG_TRACE,
196 "%s shutdown: freeing system resources.\n",
201 rc = backend_destroy();
205 ldap_pvt_thread_destroy();
207 /* should destory the above mutex */