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