]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/startup.c
Y2k copyright update
[openldap] / servers / slapd / back-ldbm / startup.c
1 /* startup.c - startup ldbm backend */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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
53 #ifdef HAVE_BERKELEY_DB2_DB_THREAD
54                 | DB_THREAD
55 #endif
56                 ;
57         int    err      = 0;
58         char   *home;
59
60         /*  if the data directory is not an absolute path, have it relative
61         to the current working directory (which should not be configured !)  */
62         if ( *li->li_directory != *LDAP_DIRSEP ) {
63                 char   cwd[MAXPATHLEN];
64
65                 (void) getcwd( cwd, MAXPATHLEN );
66                 sprintf( cwd, "%s" LDAP_DIRSEP "%s", cwd, li->li_directory );
67                 free( li->li_directory );
68                 li->li_directory = strdup( cwd );
69
70         }
71
72         /*  set the DB home directory to the data dir  */
73         home = li->li_directory;
74
75         /*  general initialization of the environment  */
76         memset( dbEnv, 0, sizeof( DB_ENV ));
77         dbEnv->db_errcall = ldbm_db_errcall;
78         dbEnv->db_errpfx  = "==>";
79
80         /*  now do the db_appinit  */
81         if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
82                 char  error[BUFSIZ];
83
84                 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
85                 else           sprintf( error, "%s\n", strerror( err ));
86
87                 fprintf( stderr,
88                                 "ldbm_back_startup(): FATAL error in db_appinit() : %s\n",
89                                 error );
90                 exit( EXIT_FAILURE );
91
92         }
93 #endif
94 }
95
96
97 void
98 ldbm_back_shutdown(
99     Backend     *be
100 )
101 {
102 #ifdef HAVE_BERKELEY_DB2
103         struct ldbminfo  *li = (struct ldbminfo *) be->be_private;
104
105         (void) db_appexit( &li->li_db_env );
106 #endif
107 }