]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/startup.c
first arg of ldbm_db_errcall could be a const char * instead of char *.
[openldap] / servers / slapd / back-ldbm / startup.c
1 /* startup.c - startup ldbm backend */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "ldapconfig.h"
11 #include "slap.h"
12 #include "back-ldbm.h"
13
14 #include "db.h"
15
16
17 void
18 ldbm_back_startup(
19     Backend     *be
20 )
21 {
22 #ifndef HAVE_BERKELEY_DB2
23         /* make sure we have one and only one big mutex */
24         static int protect = 0;
25
26         if(!protect++) {
27                 ldap_pvt_thread_mutex_init( &ldbm_big_mutex );
28         }
29
30 #else
31         struct ldbminfo  *li = (struct ldbminfo *) be->be_private;
32         DB_ENV           *dbEnv = &li->li_db_env;
33         int    envFlags = DB_CREATE | DB_THREAD;
34         int    err      = 0;
35         char   *home;
36
37         /*  if the data directory is not an absolute path, have it relative
38         to the current working directory (which should not be configured !)  */
39         if ( *li->li_directory != *DEFAULT_DIRSEP ) {
40                 char   cwd[MAXPATHLEN];
41
42                 (void) getcwd( cwd, MAXPATHLEN );
43                 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
44                 free( li->li_directory );
45                 li->li_directory = strdup( cwd );
46
47         }
48
49         /*  set the DB home directory to the data dir  */
50         home = li->li_directory;
51
52         /*  general initialization of the environment  */
53         memset( dbEnv, 0, sizeof( DB_ENV ));
54         dbEnv->db_errcall = ldbm_db_errcall;
55         dbEnv->db_errpfx  = "==>";
56
57         /*  now do the db_appinit  */
58         if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
59                 char  error[BUFSIZ];
60
61                 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
62                 else           sprintf( error, "%s\n", strerror( err ));
63
64                 fprintf( stderr,
65                                 "ldbm_back_startup(): FATAL error in db_appinit() : %s\n",
66                                 error );
67                 exit( 1 );
68
69         }
70 #endif
71 }
72
73
74 void
75 ldbm_back_shutdown(
76     Backend     *be
77 )
78 {
79 #ifdef HAVE_BERKELEY_DB2
80         struct ldbminfo  *li = (struct ldbminfo *) be->be_private;
81
82         (void) db_appexit( &li->li_db_env );
83 #endif
84 }
85
86
87 #ifdef HAVE_BERKELEY_DB2
88
89 void
90 ldbm_db_errcall( const char *prefix, char *message )
91 {
92         Debug( LDAP_DEBUG_ANY, "ldbm_db_errcall(): %s %s", prefix, message, 0 );
93 }
94
95 #endif  /*  HAVE_BERKELEY_DB2  */
96