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;
44 ldap_pvt_thread_mutex_t crypt_mutex;
48 long num_ops_initiated;
49 long num_ops_completed;
50 ldap_pvt_thread_mutex_t num_ops_mutex;
52 long num_entries_sent;
56 ldap_pvt_thread_mutex_t num_sent_mutex;
58 * these mutexes must be used when calling the entry2str()
59 * routine since it returns a pointer to static data.
61 ldap_pvt_thread_mutex_t entry2str_mutex;
62 ldap_pvt_thread_mutex_t replog_mutex;
64 static const char* slap_name = NULL;
65 int slapMode = SLAP_UNDEFINED_MODE;
67 static ldap_pvt_thread_mutex_t currenttime_mutex;
70 slap_init( int mode, const char *name )
76 if( slapMode != SLAP_UNDEFINED_MODE ) {
77 Debug( LDAP_DEBUG_ANY,
78 "%s init: init called twice (old=%d, new=%d)\n",
79 name, slapMode, mode );
85 switch ( slapMode & SLAP_MODE ) {
86 case SLAP_SERVER_MODE:
88 Debug( LDAP_DEBUG_TRACE,
89 "%s init: initiated %s.\n", name,
90 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
95 (void) ldap_pvt_thread_initialize();
97 ldap_pvt_thread_pool_init(&connection_pool, 0, 0);
99 ldap_pvt_thread_mutex_init( ¤ttime_mutex );
100 ldap_pvt_thread_mutex_init( &entry2str_mutex );
101 ldap_pvt_thread_mutex_init( &replog_mutex );
102 ldap_pvt_thread_mutex_init( &num_ops_mutex );
103 ldap_pvt_thread_mutex_init( &num_sent_mutex );
105 ldap_pvt_thread_mutex_init( &gmtime_mutex );
107 ldap_pvt_thread_mutex_init( &crypt_mutex );
110 rc = backend_init( );
114 Debug( LDAP_DEBUG_ANY,
115 "%s init: undefined mode (%d).\n", name, mode, 0 );
123 int slap_startup( Backend *be )
127 Debug( LDAP_DEBUG_TRACE,
128 "%s startup: initiated.\n",
131 rc = backend_startup( be );
140 int slap_shutdown( Backend *be )
144 Debug( LDAP_DEBUG_TRACE,
145 "%s shutdown: initiated\n",
150 /* let backends do whatever cleanup they need to do */
151 rc = backend_shutdown( be );
156 int slap_destroy(void)
160 Debug( LDAP_DEBUG_TRACE,
161 "%s shutdown: freeing system resources.\n",
164 rc = backend_destroy();
168 ldap_pvt_thread_destroy();
170 /* should destory the above mutex */
174 /* should create a utils.c for these */
175 time_t slap_get_time(void)
178 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
180 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );