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 ldap_pvt_thread_mutex_t gmtime_mutex;
43 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
44 ldap_pvt_thread_mutex_t passwd_mutex;
46 ldap_pvt_thread_mutex_t ad_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;
68 static ldap_pvt_thread_mutex_t currenttime_mutex;
71 slap_init( int mode, const char *name )
77 if( slapMode != SLAP_UNDEFINED_MODE ) {
79 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
80 "init: %s init called twice (old=%d, new=%d)\n",
81 name, slapMode, mode ));
83 Debug( LDAP_DEBUG_ANY,
84 "%s init: init called twice (old=%d, new=%d)\n",
85 name, slapMode, mode );
93 switch ( slapMode & SLAP_MODE ) {
94 case SLAP_SERVER_MODE:
97 LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
98 "init: %s initiation, initiated %s.\n",
99 name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server" ));
101 Debug( LDAP_DEBUG_TRACE,
102 "%s init: initiated %s.\n", name,
103 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
110 (void) ldap_pvt_thread_initialize();
112 ldap_pvt_thread_pool_init(&connection_pool, SLAP_MAX_WORKER_THREADS, 0);
114 ldap_pvt_thread_mutex_init( ¤ttime_mutex );
115 ldap_pvt_thread_mutex_init( &entry2str_mutex );
116 ldap_pvt_thread_mutex_init( &replog_mutex );
117 ldap_pvt_thread_mutex_init( &num_ops_mutex );
118 ldap_pvt_thread_mutex_init( &num_sent_mutex );
120 ldap_pvt_thread_mutex_init( &gmtime_mutex );
121 ldap_pvt_thread_mutex_init( &ad_mutex );
122 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
123 ldap_pvt_thread_mutex_init( &passwd_mutex );
126 rc = slap_sasl_init();
129 rc = backend_init( );
135 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
136 "init: %s init, undefined mode (%d).\n", name, mode ));
138 Debug( LDAP_DEBUG_ANY,
139 "%s init: undefined mode (%d).\n", name, mode, 0 );
149 int slap_startup( Backend *be )
154 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
155 "slap_startup: %s started\n", slap_name ));
157 Debug( LDAP_DEBUG_TRACE,
158 "%s startup: initiated.\n",
163 rc = backend_startup( be );
168 int slap_shutdown( Backend *be )
173 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
174 "slap_shutdown: %s shutdown initiated.\n", slap_name));
176 Debug( LDAP_DEBUG_TRACE,
177 "%s shutdown: initiated\n",
184 /* let backends do whatever cleanup they need to do */
185 rc = backend_shutdown( be );
190 int slap_destroy(void)
195 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
196 "slap_destroy: %s freeing system resources.\n",
199 Debug( LDAP_DEBUG_TRACE,
200 "%s shutdown: freeing system resources.\n",
205 rc = backend_destroy();
209 ldap_pvt_thread_destroy();
211 /* should destory the above mutex */
215 /* should create a utils.c for these */
216 time_t slap_get_time(void)
219 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
221 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );