1 /* init.c - initialize various things */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/socket.h>
12 #include <ac/string.h>
18 * read-only global variables or variables only written by the listener
19 * thread (after they are initialized) - no need to protect them with a mutex.
24 int ldap_syslog = LDAP_DEBUG_STATS;
29 int ldap_syslog_level = LOG_DEBUG;
30 struct berval **default_referral = NULL;
35 * global variables that need mutex protection
38 ldap_pvt_thread_mutex_t active_threads_mutex;
39 ldap_pvt_thread_cond_t active_threads_cond;
41 ldap_pvt_thread_mutex_t gmtime_mutex;
43 ldap_pvt_thread_mutex_t crypt_mutex;
47 long num_ops_initiated;
48 long num_ops_completed;
49 ldap_pvt_thread_mutex_t num_ops_mutex;
51 long num_entries_sent;
55 ldap_pvt_thread_mutex_t num_sent_mutex;
57 * these mutexes must be used when calling the entry2str()
58 * routine since it returns a pointer to static data.
60 ldap_pvt_thread_mutex_t entry2str_mutex;
61 ldap_pvt_thread_mutex_t replog_mutex;
63 static char* slap_name;
64 int slapMode = SLAP_UNDEFINED_MODE;
66 static ldap_pvt_thread_mutex_t currenttime_mutex;
69 slap_init( int mode, char *name )
75 if( slapMode != SLAP_UNDEFINED_MODE ) {
76 Debug( LDAP_DEBUG_ANY,
77 "%s init: init called twice (old=%d, new=%d)\n",
78 name, slapMode, mode );
84 switch ( slapMode & SLAP_MODE ) {
85 case SLAP_SERVER_MODE:
87 Debug( LDAP_DEBUG_TRACE,
88 "%s init: initiated %s.\n",
89 name, ( mode & SLAP_TOOL_MODE ) ? "tool" : "server", 0 );
93 (void) ldap_pvt_thread_initialize();
95 ldap_pvt_thread_mutex_init( &active_threads_mutex );
96 ldap_pvt_thread_cond_init( &active_threads_cond );
98 ldap_pvt_thread_mutex_init( ¤ttime_mutex );
99 ldap_pvt_thread_mutex_init( &entry2str_mutex );
100 ldap_pvt_thread_mutex_init( &replog_mutex );
101 ldap_pvt_thread_mutex_init( &num_ops_mutex );
102 ldap_pvt_thread_mutex_init( &num_sent_mutex );
104 ldap_pvt_thread_mutex_init( &gmtime_mutex );
106 ldap_pvt_thread_mutex_init( &crypt_mutex );
109 rc = backend_init( );
113 Debug( LDAP_DEBUG_ANY,
114 "%s init: undefined mode (%d).\n", name, mode, 0 );
122 int slap_startup( Backend *be )
126 Debug( LDAP_DEBUG_TRACE,
127 "%s startup: initiated.\n",
130 rc = backend_startup( be );
139 int slap_shutdown( Backend *be )
143 Debug( LDAP_DEBUG_TRACE,
144 "%s shutdown: initiated\n",
149 /* let backends do whatever cleanup they need to do */
150 rc = backend_shutdown( be );
155 int slap_destroy(void)
159 Debug( LDAP_DEBUG_TRACE,
160 "%s shutdown: freeing system resources.\n",
163 rc = backend_destroy();
167 ldap_pvt_thread_destroy();
169 /* should destory the above mutex */
173 /* should create a utils.c for these */
174 time_t slap_get_time(void)
177 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
179 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );