11 #if defined(HAVE_FTOK) && defined(HAVE_SYS_IPC_H)
19 #define _RPMTAG_INTERNAL
21 #define _RPMDB_INTERNAL
26 #if !defined(DB_CLIENT)
27 #define DB_CLIENT DB_RPCCLIENT
83 static const char * bfstring(
unsigned int x,
const char * xbf)
86 static char digits[] =
"0123456789abcdefghijklmnopqrstuvwxyz";
87 static char buf[BUFSIZ];
92 radix = (s != NULL ? *s++ : 16);
94 if (radix <= 1 || radix >= 32)
99 case 8: *t++ =
'0';
break;
100 case 16: *t++ =
'0'; *t++ =
'x';
break;
105 do { i++; k /= radix; }
while (k);
110 do { --i; t[i] = digits[k % radix]; k /= radix; }
while (k);
115 while ((c = *s++) !=
'\0') {
116 if (c >
' ')
continue;
119 if (!(x & k))
continue;
121 if (t == te) *t++ =
'=';
128 if (t > te) *t++ =
'>';
134 static const char * dbtFlags =
135 "\20\1APPMALLOC\2ISSET\3MALLOC\4PARTIAL\5REALLOC\6USERMEM\7DUPOK";
137 static const char * dbenvOpenFlags =
138 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17CDB\20LOCK\21LOG\22MPOOL\23REP\24TXN\25LOCKDOWN\26PRIVATE\27RECOVER_FATAL\30REGISTER\31SYSTEM_MEM";
140 static const char * dbOpenFlags =
141 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17EXCL\20FCNTL_LOCKING\21NO_AUTO_COMMIT\22RDWRMASTER\23WRITEOPEN";
143 static const char * dbenvSetFlags =
144 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17CDB_ALLDB\20DIRECT_DB\21DIRECT_LOG\22DSYNC_DB\23DSYNC_LOG\24LOG_AUTOREMOVE\25LOG_INMEMORY\26NOLOCKING\27NOPANIC\30OVERWRITE\31PANIC_ENV\36REGION_INIT\37TIME_NOTGRANTED\40YIELDCPU";
146 static const char * dbSetFlags =
147 "\20\1CREATE\2DURABLE_UNKNOWN\3FORCE\4MULTIVERSION\5NOMMAP\6RDONLY\7RECOVER\10THREAD\11TRUNCATE\12TXN_NOSYNC\13TXN_NOT_DURABLEi\14TXN_WRITE_NOSYNC\15USE_ENVIRON\16USE_ENVIRON_ROOT\17CHKSUM\20DUP\21DUPSORT\22ENCRYPT\23INORDER\24RECNUM\25RENUMBER\26REVSPLITOFF\27SNAPSHOT";
149 static const char * dbiModeFlags =
150 "\20\1WRONLY\2RDWR\7CREAT\10EXCL\11NOCTTY\12TRUNC\13APPEND\14NONBLOCK\15SYNC\16ASYNC\17DIRECT\20LARGEFILE\21DIRECTORY\22NOFOLLOW";
156 int error,
int printit)
191 while (dbix < rpmdb->db_ndbi) {
192 if (dbi->dbi_rpmtag == dbiTags->tag)
198 return tagName(dbi->dbi_rpmtag);
203 const char * dbsubfile)
208 DB_ENV * dbenv = rpmdb->db_dbenv;
214 rc = dbenv->close(dbenv, 0);
221 if (rpmdb->db_remove_env) {
225 xx = db_env_create(&dbenv, 0);
227 if (!xx && dbenv != NULL) {
229 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR != 0) || (DB_VERSION_MAJOR == 4)
230 xx = dbenv->remove(dbenv, dbhome, DB_FORCE);
232 xx = dbenv->remove(dbenv, dbhome, NULL, 0);
251 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5)
260 static int db3is_alive(
DB_ENV *dbenv, pid_t pid,
268 case DB_MUTEX_PROCESS_ONLY:
271 is_alive = (!(kill(pid, 0) < 0 &&
errno == ESRCH));
281 const char * dbsubfile,
287 static int oneshot = 0;
295 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR != 0) || (DB_VERSION_MAJOR == 4)
296 xx = db_env_set_func_open((
int (*)(
const char *,
int, ...))
Open);
307 if (rpmdb->db_errfile == NULL)
308 rpmdb->db_errfile = stderr;
311 eflags = (dbi->dbi_oeflags | dbi->dbi_eflags);
314 if (eflags & DB_JOINENV) eflags &= DB_JOINENV;
318 dbhome, dbfile, prDbiOpenFlags(eflags, 1));
321 if (dbi->dbi_host == NULL)
325 if ((dbi->dbi_eflags & DB_SYSTEM_MEM) && dbi->dbi_shmkey == 0) {
326 #if defined(HAVE_FTOK)
327 dbi->dbi_shmkey = ftok(dbhome, 0);
329 dbi->dbi_shmkey = 0x44631380;
333 rc = db_env_create(&dbenv, dbi->dbi_ecflags);
335 if (dbenv == NULL || rc)
346 dbenv->set_errcall(dbenv, (
void *)rpmdb->db_errcall);
348 dbenv->set_errfile(dbenv, rpmdb->db_errfile);
349 dbenv->set_errpfx(dbenv, rpmdb->db_errpfx);
357 if ((dbi->dbi_ecflags &
DB_CLIENT) && dbi->dbi_host) {
361 if ((home = strrchr(dbhome,
'/')) != NULL)
364 while (retry++ < 5) {
366 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3) || (DB_VERSION_MAJOR == 4)
367 xx = dbenv->set_rpc_server(dbenv, NULL, dbi->dbi_host,
368 dbi->dbi_cl_timeout, dbi->dbi_sv_timeout, 0);
371 xx = dbenv->set_server(dbenv, dbi->dbi_host,
372 dbi->dbi_cl_timeout, dbi->dbi_sv_timeout, 0);
380 #if !(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
381 xx = dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT,
382 (dbi->dbi_verbose & DB_VERB_CHKPOINT));
384 xx = dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK,
385 (dbi->dbi_verbose & DB_VERB_DEADLOCK));
386 xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY,
387 (dbi->dbi_verbose & DB_VERB_RECOVERY));
388 #if defined(DB_VERB_REGISTER)
389 xx = dbenv->set_verbose(dbenv, DB_VERB_REGISTER,
390 (dbi->dbi_verbose & DB_VERB_REGISTER));
392 #if defined(DB_VERB_REPLICATION)
393 xx = dbenv->set_verbose(dbenv, DB_VERB_REPLICATION,
394 (dbi->dbi_verbose & DB_VERB_REPLICATION));
396 xx = dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR,
397 (dbi->dbi_verbose & DB_VERB_WAITSFOR));
398 #if defined(DB_VERB_FILEOPS)
399 xx = dbenv->set_verbose(dbenv, DB_VERB_FILEOPS,
400 (dbi->dbi_verbose & DB_VERB_FILEOPS));
402 #if defined(DB_VERB_FILEOPS_ALL)
403 xx = dbenv->set_verbose(dbenv, DB_VERB_FILEOPS_ALL,
404 (dbi->dbi_verbose & DB_VERB_FILEOPS_ALL));
407 if (dbi->dbi_mmapsize) {
408 xx = dbenv->set_mp_mmapsize(dbenv, dbi->dbi_mmapsize);
411 if (dbi->dbi_tmpdir) {
415 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
416 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
419 tmpdir =
rpmGenPath(root, dbi->dbi_tmpdir, NULL);
421 xx = dbenv->set_tmp_dir(dbenv, tmpdir);
423 tmpdir =
_free(tmpdir);
429 if (dbi->dbi_lk_detect) {
430 xx = dbenv->set_lk_detect(dbenv, dbi->dbi_lk_detect);
433 #if !(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
434 if (dbi->dbi_lk_max_lockers) {
435 xx = dbenv->set_lk_max_lockers(dbenv, dbi->dbi_lk_max_lockers);
438 if (dbi->dbi_lk_max_locks) {
439 xx = dbenv->set_lk_max_locks(dbenv, dbi->dbi_lk_max_locks);
442 if (dbi->dbi_lk_max_objects) {
443 xx = dbenv->set_lk_max_objects(dbenv, dbi->dbi_lk_max_objects);
447 if (dbi->dbi_lg_bsize) {
448 xx = dbenv->set_lg_bsize(dbenv, dbi->dbi_lg_bsize);
451 if (dbi->dbi_lg_dir) {
452 xx = dbenv->set_lg_dir(dbenv, dbi->dbi_lg_dir);
455 if (dbi->dbi_lg_filemode) {
456 xx = dbenv->set_lg_filemode(dbenv, dbi->dbi_lg_filemode);
459 if (dbi->dbi_lg_max) {
460 xx = dbenv->set_lg_max(dbenv, dbi->dbi_lg_max);
463 if (dbi->dbi_lg_regionmax) {
464 xx = dbenv->set_lg_regionmax(dbenv, dbi->dbi_lg_regionmax);
470 if (dbi->dbi_cachesize) {
471 xx = dbenv->set_cachesize(dbenv, 0, dbi->dbi_cachesize, 0);
476 if (dbi->dbi_mutex_align) {
477 xx = dbenv->mutex_set_align(dbenv, dbi->dbi_mutex_align);
480 if (dbi->dbi_mutex_increment) {
481 xx = dbenv->mutex_set_increment(dbenv, dbi->dbi_mutex_increment);
484 if (dbi->dbi_mutex_max) {
485 xx = dbenv->mutex_set_max(dbenv, dbi->dbi_mutex_max);
488 if (dbi->dbi_mutex_tas_spins) {
489 xx = dbenv->mutex_set_tas_spins(dbenv, dbi->dbi_mutex_tas_spins);
504 if (dbi->dbi_tx_max) {
505 xx = dbenv->set_tx_max(dbenv, dbi->dbi_tx_max);
516 if (dbi->dbi_no_fsync) {
517 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR != 0) || (DB_VERSION_MAJOR == 4)
525 if (dbi->dbi_shmkey) {
526 xx = dbenv->set_shm_key(dbenv, dbi->dbi_shmkey);
530 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5)
533 dbenv->set_msgfile(dbenv, rpmdb->db_errfile);
536 if (dbi->dbi_thread_count >= 8) {
537 xx = dbenv->set_thread_count(dbenv, dbi->dbi_thread_count);
542 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR != 0) || (DB_VERSION_MAJOR == 4)
543 rc = (dbenv->open)(dbenv, dbhome, eflags, dbi->dbi_perms);
545 rc = (dbenv->open)(dbenv, dbhome, NULL, eflags, dbi->dbi_perms);
548 #if defined(DB_VERSION_MISMATCH)
549 if (rc == DB_VERSION_MISMATCH) xx = 0;
551 if (rc == EINVAL) xx = 0;
552 rc =
cvtdberr(dbi,
"dbenv->open", rc, xx);
556 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5)
557 if (!rpmdb->db_verifying && dbi->dbi_thread_count >= 8) {
559 xx = dbenv->set_isalive(dbenv, db3is_alive);
562 xx = dbenv->failchk(dbenv, 0);
564 if (xx == DB_RUNRECOVERY) {
577 xx = dbenv->close(dbenv, 0);
588 DB * db = dbi->dbi_db;
593 rc = db->sync(db, flags);
594 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
598 _printit = (rc == DB_INCOMPLETE ? 0 :
_debug);
600 rc =
cvtdberr(dbi,
"db->sync", rc, _printit);
611 if (dbcp) *dbcp = NULL;
612 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
613 rc = dbcursor->dup(dbcursor, dbcp, flags);
616 rc = dbcursor->c_dup(dbcursor, dbcp, flags);
633 if (dbcursor != NULL) {
634 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
635 rc = dbcursor->close(dbcursor);
638 rc = dbcursor->c_close(dbcursor);
647 DBC ** dbcp,
unsigned int dbiflags)
651 DB * db = dbi->dbi_db;
652 DBC * dbcursor = NULL;
659 (dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
665 rc = db->cursor(db, txnid, &dbcursor, flags);
681 DB * db = dbi->dbi_db;
685 if (dbcursor == NULL) {
686 rc = db->put(db, dbi->dbi_txnid, key, data, 0);
689 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
690 rc = dbcursor->put(dbcursor, key, data,
DB_KEYLAST);
693 rc = dbcursor->c_put(dbcursor, key, data,
DB_KEYLAST);
707 DB * db = dbi->dbi_db;
711 if (dbcursor == NULL) {
712 rc = db->del(db, dbi->dbi_txnid, key, flags);
718 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
719 rc = dbcursor->get(dbcursor, key, data,
DB_SET);
722 rc =
cvtdberr(dbi,
"dbcursor->get", rc, _printit);
724 rc = dbcursor->c_get(dbcursor, key, data,
DB_SET);
727 rc =
cvtdberr(dbi,
"dbcursor->c_get", rc, _printit);
731 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
732 rc = dbcursor->del(dbcursor, flags);
735 rc = dbcursor->c_del(dbcursor, flags);
751 DB * db = dbi->dbi_db;
756 if (dbcursor == NULL) {
758 rc = db->get(db, dbi->dbi_txnid, key, data, 0);
761 rc =
cvtdberr(dbi,
"db->get", rc, _printit);
763 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
765 rc = dbcursor->get(dbcursor, key, data, flags);
769 _printit = (rc == DB_BUFFER_SMALL ? 0 : _printit);
770 rc =
cvtdberr(dbi,
"dbcursor->get", rc, _printit);
773 rc = dbcursor->c_get(dbcursor, key, data, flags);
776 rc =
cvtdberr(dbi,
"dbcursor->c_get", rc, _printit);
786 DBT * data,
unsigned int flags)
790 DB * db = dbi->dbi_db;
795 assert(dbcursor != NULL);
797 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
799 rc = dbcursor->pget(dbcursor, key, pkey, data, flags);
802 rc =
cvtdberr(dbi,
"dbcursor->pget", rc, _printit);
805 rc = dbcursor->c_pget(dbcursor, key, pkey, data, flags);
808 rc =
cvtdberr(dbi,
"dbcursor->c_pget", rc, _printit);
816 unsigned int * countp,
821 db_recno_t count = 0;
825 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 6)
826 rc = dbcursor->count(dbcursor, &count, flags);
829 rc = dbcursor->c_count(dbcursor, &count, flags);
833 if (countp) *countp = count;
840 DB * db = dbi->dbi_db;
844 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3 && DB_VERSION_PATCH >= 11) \
845 || (DB_VERSION_MAJOR == 4)
847 rc = db->get_byteswapped(db, &isswapped);
851 rc = db->get_byteswapped(db);
862 DB * db = dbi->dbi_db;
863 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
869 #if defined(DB_FAST_STAT)
875 dbi->dbi_stats =
_free(dbi->dbi_stats);
877 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3) || (DB_VERSION_MAJOR == 4)
878 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
879 rc = db->stat(db, txnid, &dbi->dbi_stats, flags);
881 rc = db->stat(db, &dbi->dbi_stats, flags);
884 rc = db->stat(db, &dbi->dbi_stats, NULL, flags);
892 int (*callback)(
DB *,
const DBT *,
const DBT *,
DBT *),
897 DB * db = dbi->dbi_db;
898 DB * secondary = dbisecondary->dbi_db;
902 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
906 rc = db->associate(db, txnid, secondary, callback, flags);
909 rc = db->associate(db, secondary, callback, flags);
923 DB * db = dbi->dbi_db;
928 rc = db->join(db, curslist, dbcp, flags);
942 const char * urlfn = NULL;
947 const char * dbsubfile;
948 DB * db = dbi->dbi_db;
958 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
959 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
961 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
970 (void)
urlPath(urlfn, &dbhome);
971 if (dbi->dbi_temporary) {
976 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
977 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
979 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
985 rc = db->close(db, 0);
987 _printit = (rc == ENOENT ? 0 :
_debug);
988 rc =
cvtdberr(dbi,
"db->close", rc, _printit);
989 db = dbi->dbi_db = NULL;
992 dbhome, (dbfile ? dbfile : dbiBN));
996 if (rpmdb->db_dbenv != NULL && dbi->dbi_use_dbenv) {
997 if (rpmdb->db_opens == 1) {
999 xx =
db_fini(dbi, (dbhome ? dbhome :
""), dbfile, dbsubfile);
1001 rpmdb->db_dbenv = NULL;
1006 if (dbi->dbi_verify_on_close && !dbi->dbi_temporary) {
1011 rc = db_env_create(&dbenv, 0);
1014 if (rc || dbenv == NULL)
goto exit;
1018 dbenv->set_errcall(dbenv, (
void *)rpmdb->db_errcall);
1020 dbenv->set_errfile(dbenv, rpmdb->db_errfile);
1021 dbenv->set_errpfx(dbenv, rpmdb->db_errpfx);
1024 #if !(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
1025 xx = dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT,
1026 (dbi->dbi_verbose & DB_VERB_CHKPOINT));
1028 xx = dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK,
1029 (dbi->dbi_verbose & DB_VERB_DEADLOCK));
1030 xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY,
1031 (dbi->dbi_verbose & DB_VERB_RECOVERY));
1032 xx = dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR,
1033 (dbi->dbi_verbose & DB_VERB_WAITSFOR));
1035 if (dbi->dbi_tmpdir) {
1037 const char * tmpdir =
rpmGenPath(root, dbi->dbi_tmpdir, NULL);
1039 rc = dbenv->set_tmp_dir(dbenv, tmpdir);
1041 tmpdir =
_free(tmpdir);
1045 eflags = DB_CREATE | DB_INIT_MPOOL |
DB_PRIVATE | DB_USE_ENVIRON;
1046 rc = (dbenv->open)(dbenv, dbhome, eflags, 0);
1051 rc = db_create(&db, dbenv, 0);
1057 const char * dbf =
rpmGetPath(dbhome,
"/", dbfile, NULL);
1060 rc = db->verify(db, dbf, NULL, NULL, flags);
1064 (dbhome ? dbhome :
""),
1065 (dbfile ? dbfile : dbiBN));
1074 xx = dbenv->close(dbenv, 0);
1076 if (rc == 0 && xx) rc = xx;
1082 urlfn =
_free(urlfn);
1103 extern struct _dbiVec db3vec;
1105 const char * urlfn = NULL;
1108 const char * dbhome;
1109 const char * dbfile;
1110 const char * dbsubfile;
1118 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
1121 DBTYPE dbi_type = DB_UNKNOWN;
1132 if ((dbi = db3New(rpmdb, rpmtag)) == NULL)
1143 root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
1144 if ((root[0] ==
'/' && root[1] ==
'\0') || rpmdb->db_chrootDone)
1146 home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);
1155 (void)
urlPath(urlfn, &dbhome);
1156 if (dbi->dbi_temporary) {
1161 dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
1162 dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : dbiBN);
1164 dbfile = (dbi->dbi_file ? dbi->dbi_file : dbiBN);
1169 oflags = (dbi->dbi_oeflags | dbi->dbi_oflags);
1170 oflags &= ~DB_TRUNCATE;
1173 if ( dbi->dbi_mode & O_EXCL) oflags |=
DB_EXCL;
1179 if (dbi->dbi_temporary) {
1180 oflags |= DB_CREATE;
1181 dbi->dbi_oeflags |= DB_CREATE;
1182 oflags &= ~DB_RDONLY;
1183 dbi->dbi_oflags &= ~DB_RDONLY;
1185 if (!(dbi->dbi_mode & (O_RDWR|O_WRONLY))) oflags |= DB_RDONLY;
1186 if (dbi->dbi_mode & O_CREAT) {
1187 oflags |= DB_CREATE;
1188 dbi->dbi_oeflags |= DB_CREATE;
1191 if ( dbi->dbi_mode & O_TRUNC) oflags |= DB_TRUNCATE;
1198 (void)
rpmioMkpath(dbhome, 0755, getuid(), getgid());
1203 if (dbi->dbi_use_dbenv) {
1205 if (access(dbhome,
W_OK) == -1) {
1208 oflags &= ~DB_CREATE;
1212 dbi->dbi_eflags &= ~DB_JOINENV;
1214 dbi->dbi_eflags |= DB_JOINENV;
1215 dbi->dbi_oeflags &= ~DB_CREATE;
1216 dbi->dbi_oeflags &= ~DB_THREAD;
1218 dbi->dbi_use_dbenv = 0;
1222 if (dbi->dbi_temporary) {
1223 oflags |= DB_CREATE;
1224 dbi->dbi_oeflags |= DB_CREATE;
1225 oflags &= ~DB_RDONLY;
1226 dbi->dbi_oflags &= ~DB_RDONLY;
1228 oflags |= DB_RDONLY;
1230 dbi->dbi_oflags |= DB_RDONLY;
1235 const char * dbf =
rpmGetPath(dbhome,
"/__db.001", NULL);
1238 #if defined(RPM_VENDOR_OPENPKG)
1243 if (stat(dbf, &sb) == 0)
1244 size = (long)sb.st_size;
1245 if (access(dbf,
F_OK) == -1 || size == 0) {
1247 if (access(dbf,
F_OK) == -1) {
1250 dbi->dbi_oeflags |= DB_CREATE;
1251 dbi->dbi_eflags &= ~DB_JOINENV;
1255 dbi->dbi_eflags &= ~DB_JOINENV;
1257 dbi->dbi_eflags |= DB_JOINENV;
1258 dbi->dbi_oeflags &= ~DB_CREATE;
1259 dbi->dbi_oeflags &= ~DB_THREAD;
1269 if ((oflags & DB_CREATE) && (oflags & DB_RDONLY)) {
1271 const char * dbfn = (dbfile ? dbfile : dbiBN);
1273 const char * dbf =
rpmGetPath(dbhome,
"/", dbfn, NULL);
1276 if (access(dbf,
F_OK) == -1) {
1278 oflags &= ~DB_RDONLY;
1281 oflags &= ~DB_CREATE;
1285 if (!(oflags & DB_RDONLY) && access(dbf,
W_OK) == 0) {
1286 dbi->dbi_oflags &= ~DB_RDONLY;
1288 dbi->dbi_oflags |= DB_RDONLY;
1296 if (oflags & DB_CREATE)
1297 dbi_type = dbi->dbi_type;
1302 if (oflags & DB_RDONLY)
1303 dbi->dbi_verify_on_close = 0;
1305 if (dbi->dbi_use_dbenv) {
1307 if (rpmdb->db_dbenv == NULL) {
1308 static int runrecoverycount = 0;
1309 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
1314 case DB_RUNRECOVERY:
1315 if (runrecoverycount++ >= 1) {
1320 rpmdb =
rpmdbLink(rpmdb,
"DB_RUNRECOVERY");
1321 assert(rpmdb != NULL);
1322 rpmdb->db_remove_env = 1;
1323 rpmdb->db_verifying = 1;
1326 rpmdb->db_remove_env = 0;
1327 rpmdb->db_verifying = 0;
1329 dbi->dbi_oeflags |= DB_CREATE;
1330 dbi->dbi_eflags &= ~DB_JOINENV;
1331 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
1338 rpmdb->db_dbenv = dbenv;
1339 rpmdb->db_opens = 1;
1342 #if defined(DB_VERSION_MISMATCH)
1343 case DB_VERSION_MISMATCH:
1348 {
char * filename =
alloca(BUFSIZ);
1352 for (i = 0; i < 16; i++) {
1353 sprintf(filename,
"%s/__db.%03d", dbhome, i);
1355 if (
Stat(filename, &st)
1361 dbi->dbi_oeflags |= DB_CREATE;
1362 dbi->dbi_eflags &= ~DB_JOINENV;
1363 rc =
db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
1371 rpmdb->db_dbenv = dbenv;
1372 rpmdb->db_opens = 1;
1376 assert(rpmdb && rpmdb->db_dbenv);
1377 dbenv = rpmdb->db_dbenv;
1380 if (rpmdb->db_chrootDone)
1381 xx = dbenv->set_data_dir(dbenv, dbhome);
1389 dbhome, (dbfile ? dbfile : dbiBN),
1390 prDbiOpenFlags(oflags, 0), dbi->dbi_mode);
1393 static int _lockdbfd = 0;
1396 rc = db_create(&db, dbenv, dbi->dbi_cflags);
1399 if (rc == 0 && db != NULL) {
1402 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3) || (DB_VERSION_MAJOR == 4)
1404 rpmdb->db_malloc && rpmdb->db_realloc && rpmdb->db_free)
1406 rc = db->set_alloc(db,
1407 rpmdb->db_malloc, rpmdb->db_realloc, rpmdb->db_free);
1411 if (rc == 0 && rpmdb->db_malloc) {
1412 rc = db->set_malloc(db, rpmdb->db_malloc);
1418 if (rc == 0 && !dbi->dbi_use_dbenv && dbi->dbi_cachesize) {
1419 rc = db->set_cachesize(db, 0, dbi->dbi_cachesize, 0);
1428 if (rc == 0 && dbi->dbi_lorder) {
1429 rc = db->set_lorder(db, dbi->dbi_lorder);
1432 if (rc == 0 && dbi->dbi_pagesize) {
1433 rc = db->set_pagesize(db, dbi->dbi_pagesize);
1437 if (rc == 0 && oflags & DB_CREATE) {
1438 switch(dbi->dbi_type) {
1441 if (dbi->dbi_h_ffactor) {
1442 rc = db->set_h_ffactor(db, dbi->dbi_h_ffactor);
1446 if (dbi->dbi_h_nelem) {
1447 rc = db->set_h_nelem(db, dbi->dbi_h_nelem);
1451 if (dbi->dbi_h_flags) {
1452 rc = db->set_flags(db, dbi->dbi_h_flags);
1457 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR > 2) || (DB_VERSION_MAJOR == 4)
1458 if (dbi->dbi_h_hash_fcn) {
1459 rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn);
1463 if (dbi->dbi_h_dup_compare_fcn) {
1464 rc = db->set_dup_compare(db, dbi->dbi_h_dup_compare_fcn);
1472 if (dbi->dbi_bt_flags) {
1473 rc = db->set_flags(db, dbi->dbi_bt_flags);
1477 if (dbi->dbi_bt_minkey) {
1478 rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey);
1483 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR > 2) || (DB_VERSION_MAJOR == 4)
1484 if (dbi->dbi_bt_compare_fcn) {
1485 rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn);
1489 if (dbi->dbi_bt_dup_compare_fcn) {
1490 rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn);
1494 if (dbi->dbi_bt_prefix_fcn) {
1495 rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn);
1502 if (dbi->dbi_re_delim) {
1504 rc = db->set_re_delim(db, dbi->dbi_re_delim);
1508 if (dbi->dbi_re_len) {
1509 rc = db->set_re_len(db, dbi->dbi_re_len);
1513 if (dbi->dbi_re_pad) {
1514 rc = db->set_re_pad(db, dbi->dbi_re_pad);
1518 if (dbi->dbi_re_source) {
1519 rc = db->set_re_source(db, dbi->dbi_re_source);
1525 if (dbi->dbi_q_extentsize) {
1526 rc = db->set_q_extentsize(db, dbi->dbi_q_extentsize);
1535 const char * dbfullpath;
1536 const char * dbpath;
1540 nb = strlen(dbhome);
1541 if (dbfile) nb += 1 + strlen(dbfile);
1542 dbfullpath = t =
alloca(nb + 1);
1548 dbpath = (!dbi->dbi_use_dbenv && !dbi->dbi_temporary)
1549 ? dbfullpath : dbfile;
1553 dbpath = (!dbi->dbi_use_dbenv)
1554 ? dbfullpath : dbfile;
1556 dbpath = (!dbi->dbi_temporary)
1557 ? dbfullpath : dbfile;
1561 #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
1562 rc = (db->open)(db, txnid, dbpath, dbsubfile,
1563 dbi_type, oflags, dbi->dbi_perms);
1565 rc = (db->open)(db, dbpath, dbsubfile,
1566 dbi_type, oflags, dbi->dbi_perms);
1569 if (rc == 0 && dbi_type == DB_UNKNOWN) {
1570 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3 && DB_VERSION_PATCH >= 11) \
1571 || (DB_VERSION_MAJOR == 4)
1572 xx = db->get_type(db, &dbi_type);
1574 dbi->dbi_type = dbi_type;
1576 dbi->dbi_type = db->get_type(db);
1582 _printit = (rc > 0 ? 0 :
_debug);
1583 xx =
cvtdberr(dbi,
"db->open", rc, _printit);
1585 dbi->dbi_txnid = NULL;
1605 if (rc == 0 && dbi->dbi_lockdbfd &&
1606 !((dbi->dbi_ecflags &
DB_CLIENT) && dbi->dbi_host) &&
1607 (!dbi->dbi_use_dbenv || _lockdbfd++ == 0))
1611 if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
1615 memset(&l, 0,
sizeof(l));
1619 l.l_type = (dbi->dbi_mode & (O_RDWR|O_WRONLY))
1620 ? F_WRLCK : F_RDLCK;
1623 rc = fcntl(fdno, F_SETLK, (
void *) &l);
1626 rc = ((dbi->dbi_use_dbenv &&
1627 (dbi->dbi_eflags & DB_INIT_CDB) &&
1631 _(
"cannot get %s lock on %s/%s\n"),
1632 ((dbi->dbi_mode & (O_RDWR|O_WRONLY))
1633 ?
_(
"exclusive") :
_(
"shared")),
1634 dbhome, (dbfile ? dbfile :
""));
1635 }
else if (dbfile) {
1637 D_(
"locked db index %s/%s\n"),
1647 if (rc == 0 && dbi->dbi_db != NULL && dbip != NULL) {
1651 dbi->dbi_verify_on_close = 0;
1655 urlfn =
_free(urlfn);
1666 struct _dbiVec db3vec = {