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
00017
00018
00019
00020 #if defined(WITH_DB) || defined(WITH_SQLITE)
00021
00022
00023
00024 struct _dbiIndex db3dbi;
00025
00026
00027
00028 #if defined(WITH_DB)
00029 static int dbi_use_cursors;
00030 #endif
00031
00032
00033 #if defined(WITH_DB)
00034 static int dbi_tear_down;
00035 #endif
00036
00037
00040
00041 struct poptOption rdbOptions[] = {
00042
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
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
00087
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
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
00196
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
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
00318 { "cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
00319 NULL, NULL },
00320 #if defined(WITH_DB)
00321
00322
00323 { "errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
00324 NULL, NULL },
00325
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
00378
00379
00380
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
00419
00420
00421 #if defined(WITH_DB) && defined(NOTYET)
00422 DB_LOCK_NOWAIT
00423
00424 DB_LOCK_READ
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
00433
00434 { "lk_max_lockers", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_lockers, 0,
00435 NULL, NULL },
00436
00437
00438 { "lk_max_locks", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_locks, 0,
00439 NULL, NULL },
00440
00441
00442 { "lk_max_objects", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_objects, 0,
00443 NULL, NULL },
00444 #endif
00445
00446
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
00453
00454
00455 #if defined(WITH_DB)
00456
00457
00458 { "lg_bsize", 0,POPT_ARG_INT, &db3dbi.dbi_lg_bsize, 0,
00459 NULL, NULL },
00460
00461
00462 { "lg_dir", 0,POPT_ARG_STRING, &db3dbi.dbi_lg_dir, 0,
00463 NULL, NULL },
00464
00465
00466 { "lg_filemode", 0,POPT_ARG_INT, &db3dbi.dbi_lg_filemode, 0,
00467 NULL, NULL },
00468
00469
00470 { "lg_max", 0,POPT_ARG_INT, &db3dbi.dbi_lg_max, 0,
00471 NULL, NULL },
00472
00473
00474 { "lg_regionmax", 0,POPT_ARG_INT, &db3dbi.dbi_lg_regionmax, 0,
00475 NULL, NULL },
00476 #endif
00477
00478
00479 #if defined(WITH_DB)
00480 { "mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
00481 NULL, NULL },
00482
00483
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
00489
00490
00491
00492
00493
00494
00495 #endif
00496
00497
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
00505
00506 { "mutex_align", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_align, 0,
00507 NULL, NULL },
00508
00509
00510 { "mutex_increment", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_increment, 0,
00511 NULL, NULL },
00512
00513
00514 { "mutex_max", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_max, 0,
00515 NULL, NULL },
00516
00517
00518 { "mutex_tas_spins", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_tas_spins, 0,
00519 NULL, NULL },
00520 #endif
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 #if defined(WITH_DB)
00532
00533
00534 { "seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
00535 NULL, NULL },
00536 #endif
00537
00538
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
00552
00553 #if defined(WITH_DB) && defined(NOTYET)
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
00561
00562
00563
00564
00565
00566 #if defined(WITH_DB)
00567 { "tx_max", 0,POPT_ARG_INT, &db3dbi.dbi_tx_max, 0,
00568 NULL, NULL },
00569 #endif
00570
00571
00572
00573
00574
00575
00576
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
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
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
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
00682 while (*o && xisspace((int)*o))
00683 o++;
00684
00685
00686 for (oe = o; oe && *oe; oe++) {
00687 if (xisspace((int)*oe))
00688 break;
00689 if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/'))
00690 break;
00691 }
00692 if (oe && *oe)
00693 *oe++ = '\0';
00694 if (*o == '\0')
00695 continue;
00696
00697
00698 for (pe = o; pe && *pe && *pe != '='; pe++)
00699 {};
00700 p = (pe ? *pe++ = '\0', pe : NULL);
00701
00702
00703 for (tok = o; *tok == '!'; tok++)
00704 {};
00705
00706
00707 for (opt = rdbOptions; opt->longName != NULL; opt++) {
00708 if (strcmp(tok, opt->longName))
00709 continue;
00710 break;
00711 }
00712 if (opt->longName == NULL) {
00713 rpmlog(RPMLOG_ERR,
00714 _("unrecognized db option: \"%s\" ignored.\n"), o);
00715 continue;
00716 }
00717
00718
00719 argInfo = opt->argInfo;
00720 if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2))
00721 argInfo = POPT_BIT_CLR;
00722
00723
00724 switch (argInfo & POPT_ARG_MASK) {
00725
00726 case POPT_ARG_NONE:
00727 (void) poptSaveInt((int *)opt->arg, argInfo, 1L);
00728 break;
00729 case POPT_ARG_VAL:
00730 (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val);
00731 break;
00732 case POPT_ARG_STRING:
00733 { const char ** t = opt->arg;
00734
00735 if (t) {
00736
00737 *t = _free(*t);
00738
00739 *t = xstrdup( (p ? p : "") );
00740 }
00741
00742 } 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 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 } break;
00779 default:
00780 break;
00781 }
00782 }
00783
00784 }
00785
00786 dbOpts = _free(dbOpts);
00787
00788
00789 *dbi = db3dbi;
00790
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
00797 dbi->dbi_rpmdb = rpmdb;
00798
00799 dbi->dbi_rpmtag = tag;
00800
00801
00802
00803
00804
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
00815
00816 dbi->dbi_byteswapped = -1;
00817
00818 #if defined(WITH_DB)
00819 if (!dbi->dbi_use_dbenv) {
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
00831 return dbi;
00832
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