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
42 ldap_pvt_thread_mutex_t active_threads_mutex;
43 ldap_pvt_thread_cond_t active_threads_cond;
45 ldap_pvt_thread_mutex_t gmtime_mutex;
47 ldap_pvt_thread_mutex_t crypt_mutex;
51 long num_ops_initiated;
52 long num_ops_completed;
53 ldap_pvt_thread_mutex_t num_ops_mutex;
55 long num_entries_sent;
59 ldap_pvt_thread_mutex_t num_sent_mutex;
61 * these mutexes must be used when calling the entry2str()
62 * routine since it returns a pointer to static data.
64 ldap_pvt_thread_mutex_t entry2str_mutex;
65 ldap_pvt_thread_mutex_t replog_mutex;
67 static const char* slap_name = NULL;
68 int slapMode = SLAP_UNDEFINED_MODE;
70 static ldap_pvt_thread_mutex_t currenttime_mutex;
73 slap_init( int mode, const char *name )
79 if( slapMode != SLAP_UNDEFINED_MODE ) {
80 Debug( LDAP_DEBUG_ANY,
81 "%s init: init called twice (old=%d, new=%d)\n",
82 name, slapMode, mode );
88 switch ( slapMode & SLAP_MODE ) {
89 case SLAP_SERVER_MODE:
91 Debug( LDAP_DEBUG_TRACE,
92 "%s init: initiated %s.\n", name,
93 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
98 (void) ldap_pvt_thread_initialize();
100 ldap_pvt_thread_mutex_init( &active_threads_mutex );
101 ldap_pvt_thread_cond_init( &active_threads_cond );
103 ldap_pvt_thread_mutex_init( ¤ttime_mutex );
104 ldap_pvt_thread_mutex_init( &entry2str_mutex );
105 ldap_pvt_thread_mutex_init( &replog_mutex );
106 ldap_pvt_thread_mutex_init( &num_ops_mutex );
107 ldap_pvt_thread_mutex_init( &num_sent_mutex );
109 ldap_pvt_thread_mutex_init( &gmtime_mutex );
111 ldap_pvt_thread_mutex_init( &crypt_mutex );
114 rc = backend_init( );
118 Debug( LDAP_DEBUG_ANY,
119 "%s init: undefined mode (%d).\n", name, mode, 0 );
127 int slap_startup( Backend *be )
131 Debug( LDAP_DEBUG_TRACE,
132 "%s startup: initiated.\n",
135 rc = backend_startup( be );
144 int slap_shutdown( Backend *be )
148 Debug( LDAP_DEBUG_TRACE,
149 "%s shutdown: initiated\n",
154 /* let backends do whatever cleanup they need to do */
155 rc = backend_shutdown( be );
160 int slap_destroy(void)
164 Debug( LDAP_DEBUG_TRACE,
165 "%s shutdown: freeing system resources.\n",
168 rc = backend_destroy();
172 ldap_pvt_thread_destroy();
174 /* should destory the above mutex */
178 /* should create a utils.c for these */
179 time_t slap_get_time(void)
182 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
184 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );