rpm
5.2.1
|
00001 00005 #include "system.h" 00006 00007 #include <popt.h> 00008 #include <rpmlog.h> 00009 #include <rpmmacro.h> 00010 00011 #include <rpmtag.h> 00012 #define _RPMDB_INTERNAL 00013 #include "rpmdb.h" 00014 #include "debug.h" 00015 00016 /*@access rpmdb@*/ 00017 /*@access dbiIndex@*/ 00018 /*@access dbiIndexSet@*/ 00019 00020 #if defined(WITH_DB) || defined(WITH_SQLITE) 00021 00022 /*@-exportlocal -exportheadervar@*/ 00023 /*@unchecked@*/ 00024 struct _dbiIndex db3dbi; 00025 /*@=exportlocal =exportheadervar@*/ 00026 00027 /*@unchecked@*/ 00028 #if defined(WITH_DB) 00029 static int dbi_use_cursors; 00030 #endif 00031 00032 /*@unchecked@*/ 00033 #if defined(WITH_DB) 00034 static int dbi_tear_down; 00035 #endif 00036 00037 /*@-compmempass -immediatetrans -exportlocal -exportheadervar -type@*/ 00040 /*@unchecked@*/ 00041 struct poptOption rdbOptions[] = { 00042 /* XXX DB_CXX_NO_EXCEPTIONS */ 00043 #if defined(WITH_DB) && defined(DB_CLIENT) 00044 { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_CLIENT, 00045 NULL, NULL }, 00046 #endif 00047 #if defined(WITH_DB) && defined(DB_RPCCLIENT) 00048 { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT, 00049 NULL, NULL }, 00050 { "rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT, 00051 NULL, NULL }, 00052 #endif 00053 00054 #if defined(WITH_DB) && defined(DB_XA_CREATE) 00055 { "xa_create", 0,POPT_BIT_SET, &db3dbi.dbi_cflags, DB_XA_CREATE, 00056 NULL, NULL }, 00057 #endif 00058 00059 /* DB_ENV->open and DB->open */ 00060 #if defined(WITH_DB) && defined(DB_AUTO_COMMIT) 00061 { "auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_AUTO_COMMIT, 00062 NULL, NULL }, 00063 #endif 00064 #if defined(WITH_DB) && defined(DB_CREATE) 00065 { "create", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_CREATE, 00066 NULL, NULL }, 00067 #endif 00068 #if defined(WITH_DB) && defined(DB_MULTIVERSION) 00069 { "multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION, 00070 NULL, NULL }, 00071 #endif 00072 #if defined(WITH_DB) && defined(DB_NOMMAP) 00073 { "nommap", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP, 00074 NULL, NULL }, 00075 #endif 00076 #if defined(WITH_DB) && defined(DB_THREAD) 00077 { "thread", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_THREAD, 00078 NULL, NULL }, 00079 #endif 00080 00081 #if defined(WITH_DB) && defined(DB_FORCE) 00082 { "force", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE, 00083 NULL, NULL }, 00084 #endif 00085 00086 /* DB_ENV->set_flags */ 00087 /* DB_ENV->get_flags */ 00088 #if defined(WITH_DB) && defined(DB_INIT_CDB) 00089 { "cdb", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB, 00090 NULL, NULL }, 00091 #endif 00092 #if defined(WITH_DB) && defined(DB_INIT_LOCK) 00093 { "lock", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOCK, 00094 NULL, NULL }, 00095 #endif 00096 #if defined(WITH_DB) && defined(DB_INIT_LOG) 00097 { "log", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOG, 00098 NULL, NULL }, 00099 #endif 00100 #if defined(WITH_DB) && defined(DB_INIT_MPOOL) 00101 { "mpool", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_MPOOL, 00102 NULL, NULL }, 00103 #endif 00104 #if defined(WITH_DB) && defined(DB_INIT_REP) 00105 { "rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP, 00106 NULL, NULL }, 00107 #endif 00108 #if defined(WITH_DB) && defined(DB_INIT_TXN) 00109 { "txn", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_TXN, 00110 NULL, NULL }, 00111 #endif 00112 00113 #ifdef DYING /* XXX compatibly defined to 0 in db-4.5.20 */ 00114 { "joinenv", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV, 00115 NULL, NULL }, 00116 #endif 00117 #if defined(WITH_DB) && defined(DB_LOCKDOWN) 00118 { "lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN, 00119 NULL, NULL }, 00120 #endif 00121 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_PRIVATE) 00122 { "private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE, 00123 NULL, NULL }, 00124 #endif 00125 #if defined(WITH_DB) && defined(DB_RECOVER) 00126 { "recover", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER, 00127 NULL, NULL }, 00128 #endif 00129 #if defined(WITH_DB) && defined(DB_RECOVER_FATAL) 00130 { "recover_fatal", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER_FATAL, 00131 NULL, NULL }, 00132 #endif 00133 #if defined(WITH_DB) && defined(DB_REGISTER) 00134 { "register", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_REGISTER, 00135 NULL, NULL }, 00136 #endif 00137 #if defined(WITH_DB) && defined(DB_SYSTEM_MEM) 00138 { "shared", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM, 00139 NULL, NULL }, 00140 #endif 00141 #if defined(WITH_DB) && defined(DB_TXN_NOSYNC) 00142 { "txn_nosync", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_TXN_NOSYNC, 00143 NULL, NULL }, 00144 #endif 00145 #if defined(WITH_DB) && defined(DB_USE_ENVIRON_ROOT) 00146 { "use_environ_root", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT, 00147 NULL, NULL }, 00148 #endif 00149 #if defined(WITH_DB) && defined(DB_USE_ENVIRON) 00150 { "use_environ", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON, 00151 NULL, NULL }, 00152 #endif 00153 #if defined(WITH_DB) && defined(DB_IGNORE_LEASE) 00154 { "ignore_lease", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_IGNORE_LEASE, 00155 NULL, NULL }, 00156 #endif 00157 00158 #if defined(WITH_DB) && defined(DB_TXN_SYNC) 00159 { "txn_sync", 0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC, 00160 NULL, NULL }, 00161 #endif 00162 #if defined(WITH_DB) && defined(DB_TXN_NOWAIT) 00163 { "txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT, 00164 NULL, NULL }, 00165 #endif 00166 #if defined(WITH_DB) && defined(DB_TXN_WAIT) 00167 { "txn_wait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_WAIT, 00168 NULL, NULL }, 00169 #endif 00170 00171 #if defined(WITH_DB) && defined(NOTYET) 00172 DB_AUTO_COMMIT 00173 DB_CDB_ALLDB 00174 DB_DIRECT_DB 00175 DB_DIRECT_LOG 00176 DB_DSYNC_DB 00177 DB_DSYNC_LOG 00178 DB_LOG_AUTOREMOVE 00179 DB_LOG_BUFFER_FULL /* ??? */ 00180 DB_LOG_INMEMORY 00181 DB_NOLOCKING 00182 DB_MULTIVERSION 00183 DB_NOMMAP 00184 DB_NOPANIC 00185 DB_OVERWRITE 00186 DB_PANIC_ENVIRONMENT 00187 DB_REGION_INIT 00188 DB_TIME_NOTGRANTED 00189 DB_TXN_NOSYNC 00190 DB_TXN_SNAPSHOT 00191 DB_WRITE_NOSYNC 00192 DB_YIELDCPU 00193 #endif 00194 00195 /* DB->set_flags */ 00196 /* DB->get_flags */ 00197 #if defined(WITH_DB) && defined(NOTYET) 00198 DB_CHKSUM 00199 DB_ENCRYPT 00200 DB_TXN_NOT_DURABLE 00201 00202 DB_DUP BTREE HASH 00203 DB_DUPSORT BTREE HASH 00204 DB_RECNUM BTREE 00205 DB_REVSPLITOFF BTREE 00206 00207 DB_INORDER QUEUE 00208 DB_RENUMBER RECNO 00209 DB_SNAPSHOT RECNO 00210 #endif 00211 00212 /* DB->open */ 00213 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_EXCL) 00214 { "excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL, 00215 NULL, NULL }, 00216 #endif 00217 #if defined(WITH_DB) && defined(DB_FCNTL_LOCKING) 00218 { "fcntl_locking",0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_FCNTL_LOCKING, 00219 NULL, NULL }, 00220 #endif 00221 #if defined(WITH_DB) && defined(DB_NO_AUTO_COMMIT) && defined(NOTYET) 00222 { "noautocommit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT, 00223 NULL, NULL }, 00224 #endif 00225 #if defined(WITH_DB) && defined(DB_RDONLY) 00226 { "rdonly", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY, 00227 NULL, NULL }, 00228 #endif 00229 #if defined(WITH_DB) && defined(DB_RDWRMASTER) && defined(NOTYET) 00230 { "rdwrmaster", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDWRMASTER, 00231 NULL, NULL }, 00232 #endif 00233 #if defined(WITH_DB) && defined(NOTYET) 00234 DB_READ_UNCOMITTED 00235 #endif 00236 #if defined(WITH_DB) && defined(DB_TRUNCATE) 00237 { "truncate", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE, 00238 NULL, NULL }, 00239 #endif 00240 #if defined(WITH_DB) && defined(DB_WRITEOPEN) 00241 { "writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN, 00242 NULL, NULL }, 00243 #endif 00244 00245 #if defined(WITH_DB) 00246 { "btree", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_BTREE, 00247 NULL, NULL }, 00248 { "hash", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_HASH, 00249 NULL, NULL }, 00250 { "recno", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_RECNO, 00251 NULL, NULL }, 00252 { "queue", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_QUEUE, 00253 NULL, NULL }, 00254 { "unknown", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_UNKNOWN, 00255 NULL, NULL }, 00256 #endif 00257 00258 { "root", 0,POPT_ARG_STRING, &db3dbi.dbi_root, 0, 00259 NULL, NULL }, 00260 { "home", 0,POPT_ARG_STRING, &db3dbi.dbi_home, 0, 00261 NULL, NULL }, 00262 { "file", 0,POPT_ARG_STRING, &db3dbi.dbi_file, 0, 00263 NULL, NULL }, 00264 { "subfile", 0,POPT_ARG_STRING, &db3dbi.dbi_subfile, 0, 00265 NULL, NULL }, 00266 #if defined(WITH_DB) 00267 { "mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0, 00268 NULL, NULL }, 00269 #endif 00270 { "perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0, 00271 NULL, NULL }, 00272 #if defined(WITH_DB) 00273 { "shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0, 00274 NULL, NULL }, 00275 #endif 00276 { "tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0, 00277 NULL, NULL }, 00278 00279 #if defined(WITH_DB) 00280 { "host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0, 00281 NULL, NULL }, 00282 { "server", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0, 00283 NULL, NULL }, 00284 { "cl_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_cl_timeout, 0, 00285 NULL, NULL }, 00286 { "sv_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_sv_timeout, 0, 00287 NULL, NULL }, 00288 #endif 00289 00290 #if defined(WITH_DB) 00291 { "verify", 0,POPT_ARG_NONE, &db3dbi.dbi_verify_on_close, 0, 00292 NULL, NULL }, 00293 { "teardown", 0,POPT_ARG_NONE, &dbi_tear_down, 0, 00294 NULL, NULL }, 00295 { "usecursors",0,POPT_ARG_NONE, &dbi_use_cursors, 0, 00296 NULL, NULL }, 00297 { "usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0, 00298 NULL, NULL }, 00299 #endif 00300 { "nofsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_fsync, 0, 00301 NULL, NULL }, 00302 #if defined(WITH_DB) 00303 { "nodbsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_dbsync, 0, 00304 NULL, NULL }, 00305 { "lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0, 00306 NULL, NULL }, 00307 #endif 00308 { "noload", 0,POPT_ARG_NONE, &db3dbi.dbi_noload, 0, 00309 NULL, NULL }, 00310 { "temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0, 00311 NULL, NULL }, 00312 #if defined(WITH_DB) 00313 { "debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0, 00314 NULL, NULL }, 00315 #endif 00316 00317 /* XXX set_alloc */ 00318 { "cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0, 00319 NULL, NULL }, 00320 #if defined(WITH_DB) 00321 /* XXX set_dup_compare */ 00322 /* XXX set_encrypt */ 00323 { "errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0, 00324 NULL, NULL }, 00325 /* XXX set_feedback */ 00326 { "lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0, 00327 NULL, NULL }, 00328 #endif 00329 { "pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0, 00330 NULL, NULL }, 00331 00332 #if defined(WITH_DB) 00333 { "region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1, 00334 NULL, NULL }, 00335 00336 { "thread_count", 0,POPT_ARG_INT, &db3dbi.dbi_thread_count, 0, 00337 NULL, NULL }, 00338 #endif 00339 00340 #if defined(WITH_DB) && defined(DB_VERB_CHKPOINT) 00341 { "chkpoint", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_CHKPOINT, 00342 NULL, NULL }, 00343 #endif 00344 #if defined(WITH_DB) && defined(DB_VERB_DEADLOCK) 00345 { "deadlock", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_DEADLOCK, 00346 NULL, NULL }, 00347 #endif 00348 #if defined(WITH_DB) && defined(DB_VERB_RECOVERY) 00349 { "recovery", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_RECOVERY, 00350 NULL, NULL }, 00351 #endif 00352 #if defined(WITH_DB) && defined(DB_VERB_REGISTER) 00353 { "register", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REGISTER, 00354 NULL, NULL }, 00355 #endif 00356 #if defined(WITH_DB) && defined(DB_VERB_REPLICATION) 00357 { "replication", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REPLICATION, 00358 NULL, NULL }, 00359 #endif 00360 #if defined(WITH_DB) && defined(DB_VERB_WAITSFOR) 00361 { "waitsfor", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_WAITSFOR, 00362 NULL, NULL }, 00363 #endif 00364 #if defined(WITH_DB) && defined(DB_VERB_FILEOPS) 00365 { "fileops", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_FILEOPS, 00366 NULL, NULL }, 00367 #endif 00368 #if defined(WITH_DB) && defined(DB_VERB_FILEOPS_ALL) 00369 { "fileops_all",0,POPT_BIT_SET,&db3dbi.dbi_verbose, DB_VERB_FILEOPS_ALL, 00370 NULL, NULL }, 00371 #endif 00372 #if defined(WITH_DB) 00373 { "verbose", 0,POPT_ARG_VAL, &db3dbi.dbi_verbose, -1, 00374 NULL, NULL }, 00375 #endif 00376 00377 /* ==== Locking: */ 00378 /* DB_ENV->lock_detect */ 00379 /* DB_ENV->set_lk_detect */ 00380 /* DB_ENV->get_lk_detect */ 00381 #if defined(WITH_DB) && defined(DB_LOCK_DEFAULT) 00382 { "lk_default",0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_DEFAULT, 00383 NULL, NULL }, 00384 #endif 00385 #if defined(WITH_DB) && defined(DB_LOCK_EXPIRE) 00386 { "lk_expire", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_EXPIRE, 00387 NULL, NULL }, 00388 #endif 00389 #if defined(WITH_DB) && defined(DB_LOCK_MAXLOCKS) 00390 { "lk_maxlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXLOCKS, 00391 NULL, NULL }, 00392 #endif 00393 #if defined(WITH_DB) && defined(DB_LOCK_MAXWRITE) 00394 { "lk_maxwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXWRITE, 00395 NULL, NULL }, 00396 #endif 00397 #if defined(WITH_DB) && defined(DB_LOCK_MINLOCKS) 00398 { "lk_minlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINLOCKS, 00399 NULL, NULL }, 00400 #endif 00401 #if defined(WITH_DB) && defined(DB_LOCK_MINWRITE) 00402 { "lk_minwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINWRITE, 00403 NULL, NULL }, 00404 #endif 00405 #if defined(WITH_DB) && defined(DB_LOCK_OLDEST) 00406 { "lk_oldest", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_OLDEST, 00407 NULL, NULL }, 00408 #endif 00409 #if defined(WITH_DB) && defined(DB_LOCK_RANDOM) 00410 { "lk_random", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_RANDOM, 00411 NULL, NULL }, 00412 #endif 00413 #if defined(WITH_DB) && defined(DB_LOCK_YOUNGEST) 00414 { "lk_youngest",0, POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_YOUNGEST, 00415 NULL, NULL }, 00416 #endif 00417 00418 /* DB_ENV->lock_get */ 00419 /* XXX DB_ENV->set_lk_conflicts */ 00420 /* XXX DB_ENV->get_lk_conflicts */ 00421 #if defined(WITH_DB) && defined(NOTYET) 00422 DB_LOCK_NOWAIT /* flags */ 00423 00424 DB_LOCK_READ /* mode(s) */ 00425 DB_LOCK_WRITE 00426 DB_LOCK_IWRITE 00427 DB_LOCK_IREAD 00428 DB_LOCK_IWR 00429 #endif 00430 00431 #if defined(WITH_DB) 00432 /* XXX DB_ENV->set_lk_max_lockers */ 00433 /* XXX DB_ENV->get_lk_max_lockers */ 00434 { "lk_max_lockers", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_lockers, 0, 00435 NULL, NULL }, 00436 /* XXX DB_ENV->set_lk_max_locks */ 00437 /* XXX DB_ENV->get_lk_max_locks */ 00438 { "lk_max_locks", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_locks, 0, 00439 NULL, NULL }, 00440 /* XXX DB_ENV->set_lk_max_objects */ 00441 /* XXX DB_ENV->get_lk_max_objects */ 00442 { "lk_max_objects", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_objects, 0, 00443 NULL, NULL }, 00444 #endif 00445 00446 /* XXX DB_ENV->set_timeout */ 00447 #if defined(WITH_DB) && defined(NOTYET) 00448 DB_SET_LOCK_TIMEOUT 00449 DB_SET_TXN_NOW 00450 DB_SET_TXN_TIMEOUT 00451 #endif 00452 /* XXX DB_ENV->get_timeout */ 00453 00454 /* ==== Logging: */ 00455 #if defined(WITH_DB) 00456 /* XXX DB_ENV->set_lg_bsize */ 00457 /* XXX DB_ENV->get_lg_bsize */ 00458 { "lg_bsize", 0,POPT_ARG_INT, &db3dbi.dbi_lg_bsize, 0, 00459 NULL, NULL }, 00460 /* XXX DB_ENV->set_lg_dir */ 00461 /* XXX DB_ENV->get_lg_dir */ 00462 { "lg_dir", 0,POPT_ARG_STRING, &db3dbi.dbi_lg_dir, 0, 00463 NULL, NULL }, 00464 /* XXX DB_ENV->set_lg_filemode */ 00465 /* XXX DB_ENV->get_lg_filemode */ 00466 { "lg_filemode", 0,POPT_ARG_INT, &db3dbi.dbi_lg_filemode, 0, 00467 NULL, NULL }, 00468 /* XXX DB_ENV->set_lg_max */ 00469 /* XXX DB_ENV->get_lg_max */ 00470 { "lg_max", 0,POPT_ARG_INT, &db3dbi.dbi_lg_max, 0, 00471 NULL, NULL }, 00472 /* XXX DB_ENV->set_lg_regionmax */ 00473 /* XXX DB_ENV->get_lg_regionmax */ 00474 { "lg_regionmax", 0,POPT_ARG_INT, &db3dbi.dbi_lg_regionmax, 0, 00475 NULL, NULL }, 00476 #endif 00477 00478 /* ==== Memory pool: */ 00479 #if defined(WITH_DB) 00480 { "mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0, 00481 NULL, NULL }, 00482 /* XXX DB_ENV->set_mp_max_openfd */ 00483 /* XXX DB_ENV->set_mp_max_write */ 00484 { "mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0, 00485 NULL, NULL }, 00486 { "mp_mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0, 00487 NULL, NULL }, 00488 /* XXX DB_MPOOLFILE->set_clear_len */ 00489 /* XXX DB_MPOOLFILE->set_fileid */ 00490 /* XXX DB_MPOOLFILE->set_ftype */ 00491 /* XXX DB_MPOOLFILE->set_lsn_offset */ 00492 /* XXX DB_MPOOLFILE->set_maxsize */ 00493 /* XXX DB_MPOOLFILE->set_pgcookie */ 00494 /* XXX DB_MPOOLFILE->set_priority */ 00495 #endif 00496 00497 /* ==== Mutexes: */ 00498 #if defined(WITH_DB) && defined(NOTYET) 00499 DB_MUTEX_PROCESS_ONLY mutex_alloc 00500 DB_MUTEX_SELF_BLOCK mutex_alloc 00501 DB_STAT_CLEAR mutex_stat* 00502 #endif 00503 #if defined(WITH_DB) 00504 /* XXX DB_ENV->mutex_set_align */ 00505 /* XXX DB_ENV->mutex_get_align */ 00506 { "mutex_align", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_align, 0, 00507 NULL, NULL }, 00508 /* XXX DB_ENV->mutex_set_increment */ 00509 /* XXX DB_ENV->mutex_get_increment */ 00510 { "mutex_increment", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_increment, 0, 00511 NULL, NULL }, 00512 /* XXX DB_ENV->mutex_set_max */ 00513 /* XXX DB_ENV->mutex_get_max */ 00514 { "mutex_max", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_max, 0, 00515 NULL, NULL }, 00516 /* XXX DB_ENV->mutex_set_tas_spins */ 00517 /* XXX DB_ENV->mutex_get_tas_spins */ 00518 { "mutex_tas_spins", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_tas_spins, 0, 00519 NULL, NULL }, 00520 #endif 00521 00522 /* ==== Replication: */ 00523 /* XXX DB_ENV->rep_set_config */ 00524 /* XXX DB_ENV->rep_set_limit */ 00525 /* XXX DB_ENV->rep_set_nsites */ 00526 /* XXX DB_ENV->rep_set_priority */ 00527 /* XXX DB_ENV->rep_set_timeout */ 00528 /* XXX DB_ENV->rep_set_transport */ 00529 00530 /* ==== Sequences: */ 00531 #if defined(WITH_DB) 00532 /* XXX DB_SEQUENCE->set_cachesize */ 00533 /* XXX DB_SEQUENCE->get_cachesize */ 00534 { "seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0, 00535 NULL, NULL }, 00536 #endif 00537 /* XXX DB_SEQUENCE->set_flags */ 00538 /* XXX DB_SEQUENCE->get_flags */ 00539 #if defined(WITH_DB) && defined(DB_SEQ_DEC) 00540 { "seq_dec", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_DEC, 00541 NULL, NULL }, 00542 #endif 00543 #if defined(WITH_DB) && defined(DB_SEQ_INC) 00544 { "seq_inc", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_INC, 00545 NULL, NULL }, 00546 #endif 00547 #if defined(WITH_DB) && defined(DB_SEQ_WRAP) 00548 { "seq_wrap", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_WRAP, 00549 NULL, NULL }, 00550 #endif 00551 /* XXX DB_SEQUENCE->set_range */ 00552 /* XXX DB_SEQUENCE->get_range */ 00553 #if defined(WITH_DB) && defined(NOTYET) /* needs signed 64bit type */ 00554 { "seq_min", 0,POPT_ARG_INT, &db3dbi.dbi_seq_min, 0, 00555 NULL, NULL }, 00556 { "seq_max", 0,POPT_ARG_INT, &db3dbi.dbi_seq_max, 0, 00557 NULL, NULL }, 00558 #endif 00559 00560 /* ==== Transactions: */ 00561 /* XXX DB_ENV->txn_checkpoint */ 00562 /* XXX DB_ENV->txn_recover */ 00563 /* XXX DB_ENV->txn_stat */ 00564 /* XXX DB_ENV->set_timeout */ 00565 /* XXX DB_ENV->get_timeout */ 00566 #if defined(WITH_DB) 00567 { "tx_max", 0,POPT_ARG_INT, &db3dbi.dbi_tx_max, 0, 00568 NULL, NULL }, 00569 #endif 00570 /* XXX DB_ENV->set_tx_timestamp */ 00571 00572 /* XXX set_append_recno */ 00573 /* XXX set_bt_compare */ 00574 /* XXX set_bt_dup_compare */ 00575 /* XXX set_bt_minkey */ 00576 /* XXX set_bt_prefix */ 00577 #if defined(WITH_DB) && defined(DB_DUP) 00578 { "bt_dup", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP, 00579 NULL, NULL }, 00580 #endif 00581 #if defined(WITH_DB) && defined(DB_DUPSORT) 00582 { "bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT, 00583 NULL, NULL }, 00584 #endif 00585 #if defined(WITH_DB) && defined(DB_RECNUM) 00586 { "bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM, 00587 NULL, NULL }, 00588 #endif 00589 #if defined(WITH_DB) && defined(DB_REVSPLITOFF) 00590 { "bt_revsplitoff", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_REVSPLITOFF, 00591 NULL, NULL }, 00592 #endif 00593 00594 #if defined(WITH_DB) && defined(DB_DUP) 00595 { "h_dup", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP, 00596 NULL, NULL }, 00597 #endif 00598 #if defined(WITH_DB) && defined(DB_SUPSORT) 00599 { "h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT, 00600 NULL, NULL }, 00601 #endif 00602 #if defined(WITH_DB) 00603 { "h_ffactor", 0,POPT_ARG_INT, &db3dbi.dbi_h_ffactor, 0, 00604 NULL, NULL }, 00605 { "h_nelem", 0,POPT_ARG_INT, &db3dbi.dbi_h_nelem, 0, 00606 NULL, NULL }, 00607 #endif 00608 00609 #if defined(WITH_DB) && defined(DB_RENUMBER) 00610 { "re_renumber", 0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_RENUMBER, 00611 NULL, NULL }, 00612 #endif 00613 #if defined(WITH_DB) && defined(DB_SNAPSHOT) 00614 { "re_snapshot",0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_SNAPSHOT, 00615 NULL, NULL }, 00616 #endif 00617 #if defined(WITH_DB) 00618 { "re_delim", 0,POPT_ARG_INT, &db3dbi.dbi_re_delim, 0, 00619 NULL, NULL }, 00620 { "re_len", 0,POPT_ARG_INT, &db3dbi.dbi_re_len, 0, 00621 NULL, NULL }, 00622 { "re_pad", 0,POPT_ARG_INT, &db3dbi.dbi_re_pad, 0, 00623 NULL, NULL }, 00624 { "re_source", 0,POPT_ARG_STRING, &db3dbi.dbi_re_source, 0, 00625 NULL, NULL }, 00626 00627 { "q_extentsize", 0,POPT_ARG_INT, &db3dbi.dbi_q_extentsize, 0, 00628 NULL, NULL }, 00629 #endif 00630 00631 POPT_TABLEEND 00632 }; 00633 /*@=compmempass =immediatetrans =exportlocal =exportheadervar =type@*/ 00634 00635 dbiIndex db3Free(dbiIndex dbi) 00636 { 00637 if (dbi) { 00638 dbi->dbi_root = _free(dbi->dbi_root); 00639 dbi->dbi_home = _free(dbi->dbi_home); 00640 dbi->dbi_file = _free(dbi->dbi_file); 00641 dbi->dbi_subfile = _free(dbi->dbi_subfile); 00642 dbi->dbi_tmpdir = _free(dbi->dbi_tmpdir); 00643 dbi->dbi_host = _free(dbi->dbi_host); 00644 dbi->dbi_errpfx = _free(dbi->dbi_errpfx); 00645 dbi->dbi_re_source = _free(dbi->dbi_re_source); 00646 dbi->dbi_stats = _free(dbi->dbi_stats); 00647 dbi = _free(dbi); 00648 } 00649 return dbi; 00650 } 00651 00652 /*@observer@*/ /*@unchecked@*/ 00653 static const char *db3_config_default = 00654 "hash tmpdir=/var/tmp create cdb mpool mp_mmapsize=16Mb mp_size=1Mb perms=0644"; 00655 00656 dbiIndex db3New(rpmdb rpmdb, rpmTag tag) 00657 { 00658 dbiIndex dbi = xcalloc(1, sizeof(*dbi)); 00659 char * dbOpts = rpmExpand("%{_dbi_config_", tagName(tag), "}", NULL); 00660 00661 if (!(dbOpts && *dbOpts && *dbOpts != '%')) { 00662 dbOpts = _free(dbOpts); 00663 dbOpts = rpmExpand("%{_dbi_config}", NULL); 00664 if (!(dbOpts && *dbOpts && *dbOpts != '%')) { 00665 dbOpts = rpmExpand(db3_config_default, NULL); 00666 } 00667 } 00668 00669 /* Parse the options for the database element(s). */ 00670 if (dbOpts && *dbOpts && *dbOpts != '%') { 00671 char *o, *oe; 00672 char *p, *pe; 00673 00674 memset(&db3dbi, 0, sizeof(db3dbi)); 00675 /*=========*/ 00676 for (o = dbOpts; o && *o; o = oe) { 00677 struct poptOption *opt; 00678 const char * tok; 00679 int argInfo; 00680 00681 /* Skip leading white space. */ 00682 while (*o && xisspace((int)*o)) 00683 o++; 00684 00685 /* Find and terminate next key=value pair. Save next start point. */ 00686 for (oe = o; oe && *oe; oe++) { 00687 if (xisspace((int)*oe)) 00688 /*@innerbreak@*/ break; 00689 if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/')) 00690 /*@innerbreak@*/ break; 00691 } 00692 if (oe && *oe) 00693 *oe++ = '\0'; 00694 if (*o == '\0') 00695 continue; 00696 00697 /* Separate key from value, save value start (if any). */ 00698 for (pe = o; pe && *pe && *pe != '='; pe++) 00699 {}; 00700 p = (pe ? *pe++ = '\0', pe : NULL); 00701 00702 /* Skip over negation at start of token. */ 00703 for (tok = o; *tok == '!'; tok++) 00704 {}; 00705 00706 /* Find key in option table. */ 00707 for (opt = rdbOptions; opt->longName != NULL; opt++) { 00708 if (strcmp(tok, opt->longName)) 00709 /*@innercontinue@*/ continue; 00710 /*@innerbreak@*/ break; 00711 } 00712 if (opt->longName == NULL) { 00713 rpmlog(RPMLOG_ERR, 00714 _("unrecognized db option: \"%s\" ignored.\n"), o); 00715 continue; 00716 } 00717 00718 /* Toggle the flags for negated tokens, if necessary. */ 00719 argInfo = opt->argInfo; 00720 if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2)) 00721 argInfo = POPT_BIT_CLR; 00722 00723 /* Save value in template as appropriate. */ 00724 switch (argInfo & POPT_ARG_MASK) { 00725 00726 case POPT_ARG_NONE: 00727 (void) poptSaveInt((int *)opt->arg, argInfo, 1L); 00728 /*@switchbreak@*/ break; 00729 case POPT_ARG_VAL: 00730 (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val); 00731 /*@switchbreak@*/ break; 00732 case POPT_ARG_STRING: 00733 { const char ** t = opt->arg; 00734 /*@-mods@*/ 00735 if (t) { 00736 /*@-unqualifiedtrans@*/ /* FIX: opt->arg annotation in popt.h */ 00737 *t = _free(*t); 00738 /*@=unqualifiedtrans@*/ 00739 *t = xstrdup( (p ? p : "") ); 00740 } 00741 /*@=mods@*/ 00742 } /*@switchbreak@*/ break; 00743 00744 case POPT_ARG_INT: 00745 case POPT_ARG_LONG: 00746 { long aLong = strtol(p, &pe, 0); 00747 if (pe) { 00748 if (!xstrncasecmp(pe, "Mb", 2)) 00749 aLong *= 1024 * 1024; 00750 else if (!xstrncasecmp(pe, "Kb", 2)) 00751 aLong *= 1024; 00752 else if (*pe != '\0') { 00753 rpmlog(RPMLOG_ERR, 00754 _("%s has invalid numeric value, skipped\n"), 00755 opt->longName); 00756 continue; 00757 } 00758 } 00759 00760 if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) { 00761 if (aLong == LONG_MIN || aLong == LONG_MAX) { 00762 rpmlog(RPMLOG_ERR, 00763 _("%s has too large or too small long value, skipped\n"), 00764 opt->longName); 00765 continue; 00766 } 00767 (void) poptSaveLong((long *)opt->arg, argInfo, aLong); 00768 /*@switchbreak@*/ break; 00769 } else { 00770 if (aLong > INT_MAX || aLong < INT_MIN) { 00771 rpmlog(RPMLOG_ERR, 00772 _("%s has too large or too small integer value, skipped\n"), 00773 opt->longName); 00774 continue; 00775 } 00776 (void) poptSaveInt((int *)opt->arg, argInfo, aLong); 00777 } 00778 } /*@switchbreak@*/ break; 00779 default: 00780 /*@switchbreak@*/ break; 00781 } 00782 } 00783 /*=========*/ 00784 } 00785 00786 dbOpts = _free(dbOpts); 00787 00788 /*@-assignexpose@*/ 00789 /*@i@*/ *dbi = db3dbi; /* structure assignment */ 00790 /*@=assignexpose@*/ 00791 memset(&db3dbi, 0, sizeof(db3dbi)); 00792 00793 if (!(dbi->dbi_perms & 0600)) 00794 dbi->dbi_perms = 0644; 00795 dbi->dbi_mode = rpmdb->db_mode; 00796 /*@-assignexpose -newreftrans@*/ /* FIX: figger rpmdb/dbi refcounts */ 00797 /*@i@*/ dbi->dbi_rpmdb = rpmdb; 00798 /*@=assignexpose =newreftrans@*/ 00799 dbi->dbi_rpmtag = tag; 00800 00801 /* 00802 * Inverted lists have join length of 2, primary data has join length of 1. 00803 */ 00804 /*@-sizeoftype@*/ 00805 switch (tag) { 00806 case RPMDBI_PACKAGES: 00807 case RPMDBI_DEPENDS: 00808 dbi->dbi_jlen = 1 * sizeof(rpmuint32_t); 00809 break; 00810 default: 00811 dbi->dbi_jlen = 2 * sizeof(rpmuint32_t); 00812 break; 00813 } 00814 /*@=sizeoftype@*/ 00815 00816 dbi->dbi_byteswapped = -1; /* -1 unknown, 0 native order, 1 alien order */ 00817 00818 #if defined(WITH_DB) 00819 if (!dbi->dbi_use_dbenv) { /* db3 dbenv is always used now. */ 00820 dbi->dbi_use_dbenv = 1; 00821 dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV); 00822 dbi->dbi_mmapsize = 16 * 1024 * 1024; 00823 dbi->dbi_cachesize = 1 * 1024 * 1024; 00824 } 00825 00826 if ((dbi->dbi_bt_flags | dbi->dbi_h_flags) & DB_DUP) 00827 dbi->dbi_permit_dups = 1; 00828 #endif 00829 00830 /*@-globstate@*/ /* FIX: *(rdbOptions->arg) reachable */ 00831 return dbi; 00832 /*@=globstate@*/ 00833 } 00834 00835 const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags) 00836 { 00837 static char buf[256]; 00838 struct poptOption *opt; 00839 char * oe; 00840 00841 oe = buf; 00842 *oe = '\0'; 00843 for (opt = rdbOptions; opt->longName != NULL; opt++) { 00844 if (opt->argInfo != POPT_BIT_SET) 00845 continue; 00846 if (print_dbenv_flags) { 00847 if (!(opt->arg == &db3dbi.dbi_oeflags || 00848 opt->arg == &db3dbi.dbi_eflags)) 00849 continue; 00850 } else { 00851 if (!(opt->arg == &db3dbi.dbi_oeflags || 00852 opt->arg == &db3dbi.dbi_oflags)) 00853 continue; 00854 } 00855 if ((dbflags & opt->val) != opt->val) 00856 continue; 00857 if (oe != buf) 00858 *oe++ = ':'; 00859 oe = stpcpy(oe, opt->longName); 00860 dbflags &= ~opt->val; 00861 } 00862 if (dbflags) { 00863 if (oe != buf) 00864 *oe++ = ':'; 00865 sprintf(oe, "0x%x", (unsigned)dbflags); 00866 } 00867 return buf; 00868 } 00869 00870 #endif