]> git.sur5r.net Git - openldap/blob - servers/slapd/init.c
read_config() did not return a value
[openldap] / servers / slapd / init.c
1 /* init.c - initialize various things */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9 #include <ac/time.h>
10
11 #include "portable.h"
12 #include "slap.h"
13
14 /*
15  * read-only global variables or variables only written by the listener
16  * thread (after they are initialized) - no need to protect them with a mutex.
17  */
18 int             slap_debug = 0;
19
20 #ifdef LDAP_DEBUG
21 int             ldap_syslog = LDAP_DEBUG_STATS;
22 #else
23 int             ldap_syslog;
24 #endif
25
26 int             ldap_syslog_level = LOG_DEBUG;
27 char            *default_referral;
28 time_t          starttime;
29 ldap_pvt_thread_t       listener_tid;
30 int             g_argc;
31 char            **g_argv;
32
33 /*
34  * global variables that need mutex protection
35  */
36 int                             active_threads;
37 ldap_pvt_thread_mutex_t active_threads_mutex;
38 ldap_pvt_thread_cond_t  active_threads_cond;
39
40 time_t                  currenttime;
41 ldap_pvt_thread_mutex_t currenttime_mutex;
42
43 ldap_pvt_thread_mutex_t new_conn_mutex;
44
45 #ifdef SLAPD_CRYPT
46 ldap_pvt_thread_mutex_t crypt_mutex;
47 #endif
48
49 int                             num_conns;
50 long                    ops_initiated;
51 long                    ops_completed;
52 ldap_pvt_thread_mutex_t ops_mutex;
53
54 long                    num_entries_sent;
55 long                    num_bytes_sent;
56 ldap_pvt_thread_mutex_t num_sent_mutex;
57 /*
58  * these mutexes must be used when calling the entry2str()
59  * routine since it returns a pointer to static data.
60  */
61 ldap_pvt_thread_mutex_t entry2str_mutex;
62 ldap_pvt_thread_mutex_t replog_mutex;
63
64 static char* slap_name;
65 int slapMode = SLAP_UNDEFINED_MODE;
66
67 int
68 slap_init( int mode, char *name )
69 {
70         int rc;
71
72         if( slapMode != SLAP_UNDEFINED_MODE ) {
73                 Debug( LDAP_DEBUG_ANY,
74                  "%s init: init called twice (old=%d, new=%d)\n",
75                  name, slapMode, mode );
76                 return 1;
77         }
78
79         slapMode = mode;
80
81         switch ( slapMode ) {
82
83                 case SLAP_SERVER_MODE:
84                 case SLAP_TOOL_MODE:
85 #ifdef SLAPD_BDB2
86                 case SLAP_TIMEDSERVER_MODE:
87 #endif
88
89                         Debug( LDAP_DEBUG_TRACE,
90                                 "%s init: initiated %s.\n",
91                                 name, mode == SLAP_TOOL_MODE ? "tool" : "server", 0 );
92
93                         slap_name = name;
94         
95                         (void) ldap_pvt_thread_initialize();
96
97                         ldap_pvt_thread_mutex_init( &active_threads_mutex );
98                         ldap_pvt_thread_cond_init( &active_threads_cond );
99
100                         ldap_pvt_thread_mutex_init( &new_conn_mutex );
101                         ldap_pvt_thread_mutex_init( &currenttime_mutex );
102                         ldap_pvt_thread_mutex_init( &entry2str_mutex );
103                         ldap_pvt_thread_mutex_init( &replog_mutex );
104                         ldap_pvt_thread_mutex_init( &ops_mutex );
105                         ldap_pvt_thread_mutex_init( &num_sent_mutex );
106 #ifdef SLAPD_CRYPT
107                         ldap_pvt_thread_mutex_init( &crypt_mutex );
108 #endif
109
110                         rc = backend_init();
111                         break;
112
113                 default:
114                         Debug( LDAP_DEBUG_ANY,
115                                 "%s init: undefined mode (%d).\n", name, mode, 0 );
116                         rc = 1;
117                         break;
118         }
119
120         return rc;
121 }
122
123 int slap_startup(int dbnum)
124 {
125         int rc;
126
127         Debug( LDAP_DEBUG_TRACE,
128                 "%s startup: initiated.\n",
129                 slap_name, 0, 0 );
130
131         rc = backend_startup(dbnum);
132
133         return rc;
134 }
135
136 int slap_shutdown(int dbnum)
137 {
138         int rc;
139
140         Debug( LDAP_DEBUG_TRACE,
141                 "%s shutdown: initiated\n",
142                 slap_name, 0, 0 );
143
144         /* let backends do whatever cleanup they need to do */
145         rc = backend_shutdown(dbnum); 
146
147         return rc;
148 }
149
150 int slap_destroy(void)
151 {
152         int rc;
153
154         Debug( LDAP_DEBUG_TRACE,
155                 "%s shutdown: freeing system resources.\n",
156                 slap_name, 0, 0 );
157
158         rc = backend_destroy();
159
160         /* should destory the above mutex */
161         return rc;
162 }
163