]> git.sur5r.net Git - openldap/blob - servers/slapd/init.c
compare attribute type, not value
[openldap] / servers / slapd / init.c
1 /* init.c - initialize various things */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14 #include <ac/time.h>
15
16 #include "slap.h"
17
18 /*
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.
21  */
22 int             slap_debug = 0;
23
24 #ifdef LDAP_DEBUG
25 int             ldap_syslog = LDAP_DEBUG_STATS;
26 #else
27 int             ldap_syslog;
28 #endif
29
30 #ifdef LOG_DEBUG
31 int             ldap_syslog_level = LOG_DEBUG;
32 #endif
33
34 BerVarray default_referral = NULL;
35
36 /*
37  * global variables that need mutex protection
38  */
39 ldap_pvt_thread_pool_t  connection_pool;
40 int                     connection_pool_max = SLAP_MAX_WORKER_THREADS;
41 ldap_pvt_thread_mutex_t gmtime_mutex;
42 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
43 ldap_pvt_thread_mutex_t passwd_mutex;
44 #endif
45
46 unsigned long                   num_ops_initiated;
47 unsigned long                   num_ops_completed;
48 ldap_pvt_thread_mutex_t num_ops_mutex;
49
50 unsigned long                   num_entries_sent;
51 unsigned long                   num_refs_sent;
52 unsigned long                   num_bytes_sent;
53 unsigned long                   num_pdu_sent;
54 ldap_pvt_thread_mutex_t num_sent_mutex;
55 /*
56  * these mutexes must be used when calling the entry2str()
57  * routine since it returns a pointer to static data.
58  */
59 ldap_pvt_thread_mutex_t entry2str_mutex;
60 ldap_pvt_thread_mutex_t replog_mutex;
61
62 static const char* slap_name = NULL;
63 int slapMode = SLAP_UNDEFINED_MODE;
64
65 int
66 slap_init( int mode, const char *name )
67 {
68         int rc;
69
70         assert( mode );
71
72         if( slapMode != SLAP_UNDEFINED_MODE ) {
73 #ifdef NEW_LOGGING
74                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
75                            "init: %s init called twice (old=%d, new=%d)\n",
76                            name, slapMode, mode ));
77 #else
78                 Debug( LDAP_DEBUG_ANY,
79                  "%s init: init called twice (old=%d, new=%d)\n",
80                  name, slapMode, mode );
81 #endif
82
83                 return 1;
84         }
85
86         slapMode = mode;
87
88         switch ( slapMode & SLAP_MODE ) {
89                 case SLAP_SERVER_MODE:
90                 case SLAP_TOOL_MODE:
91 #ifdef NEW_LOGGING
92                         LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1,
93                                    "init: %s initiation, initiated %s.\n",
94                                    name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server" ));
95 #else
96                         Debug( LDAP_DEBUG_TRACE,
97                                 "%s init: initiated %s.\n",     name,
98                                 (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server",
99                                 0 );
100 #endif
101
102
103                         slap_name = name;
104         
105                         (void) ldap_pvt_thread_initialize();
106
107                         ldap_pvt_thread_pool_init(&connection_pool, connection_pool_max, 0);
108
109                         ldap_pvt_thread_mutex_init( &entry2str_mutex );
110                         ldap_pvt_thread_mutex_init( &replog_mutex );
111                         ldap_pvt_thread_mutex_init( &num_ops_mutex );
112                         ldap_pvt_thread_mutex_init( &num_sent_mutex );
113
114                         ldap_pvt_thread_mutex_init( &gmtime_mutex );
115 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
116                         ldap_pvt_thread_mutex_init( &passwd_mutex );
117 #endif
118
119                         rc = slap_sasl_init();
120
121                         if( rc == 0 ) {
122                                 rc = backend_init( );
123                         }
124                         break;
125
126                 default:
127 #ifdef NEW_LOGGING
128                         LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
129                                    "init: %s init, undefined mode (%d).\n", name, mode ));
130 #else
131                         Debug( LDAP_DEBUG_ANY,
132                                 "%s init: undefined mode (%d).\n", name, mode, 0 );
133 #endif
134
135                         rc = 1;
136                         break;
137         }
138
139         return rc;
140 }
141
142 int slap_startup( Backend *be )
143 {
144         int rc;
145
146 #ifdef NEW_LOGGING
147         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
148                    "slap_startup: %s started\n", slap_name ));
149 #else
150         Debug( LDAP_DEBUG_TRACE,
151                 "%s startup: initiated.\n",
152                 slap_name, 0, 0 );
153 #endif
154
155
156         rc = backend_startup( be );
157
158         return rc;
159 }
160
161 int slap_shutdown( Backend *be )
162 {
163         int rc;
164
165 #ifdef NEW_LOGGING
166         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
167                    "slap_shutdown: %s shutdown initiated.\n", slap_name));
168 #else
169         Debug( LDAP_DEBUG_TRACE,
170                 "%s shutdown: initiated\n",
171                 slap_name, 0, 0 );
172 #endif
173
174
175         slap_sasl_destroy();
176
177         /* let backends do whatever cleanup they need to do */
178         rc = backend_shutdown( be ); 
179
180         return rc;
181 }
182
183 int slap_destroy(void)
184 {
185         int rc;
186
187 #ifdef NEW_LOGGING
188         LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
189                    "slap_destroy: %s freeing system resources.\n",
190                    slap_name ));
191 #else
192         Debug( LDAP_DEBUG_TRACE,
193                 "%s shutdown: freeing system resources.\n",
194                 slap_name, 0, 0 );
195 #endif
196
197
198         rc = backend_destroy();
199
200         entry_destroy();
201
202         ldap_pvt_thread_destroy();
203
204         /* should destory the above mutex */
205         return rc;
206 }