rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

dbconfig.c
Go to the documentation of this file.
1
5 #include "system.h"
6
7 #include <popt.h>
8 #include <rpmlog.h>
9 #include <rpmmacro.h>
10
11 #include <rpmtag.h>
12 #define _RPMDB_INTERNAL
13 #include "rpmdb.h"
14 #include "debug.h"
15
16 /*@access rpmdb@*/
17 /*@access dbiIndex@*/
18 /*@access dbiIndexSet@*/
19
20 #if defined(WITH_DB) || defined(WITH_SQLITE)
21
22 /*@-exportlocal -exportheadervar@*/
23 /*@unchecked@*/
24 struct _dbiIndex db3dbi;
25 /*@=exportlocal =exportheadervar@*/
26
27 /*@unchecked@*/
28 #if defined(WITH_DB)
29 static int dbi_use_cursors;
30 #endif
31
32 /*@unchecked@*/
33 #if defined(WITH_DB)
34 static int dbi_tear_down;
35 #endif
36
37 /*@-compmempass -immediatetrans -exportlocal -exportheadervar -type@*/
40 /*@unchecked@*/
41 struct poptOption rdbOptions[] = {
42 /* XXX DB_CXX_NO_EXCEPTIONS */
43 #if defined(WITH_DB) && defined(DB_CLIENT)
44 { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_CLIENT,
45 NULL, NULL },
46 #endif
47 #if defined(WITH_DB) && defined(DB_RPCCLIENT)
48 { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
49 NULL, NULL },
50 { "rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
51 NULL, NULL },
52 #endif
53
54 #if defined(WITH_DB) && defined(DB_XA_CREATE)
55 { "xa_create", 0,POPT_BIT_SET, &db3dbi.dbi_cflags, DB_XA_CREATE,
56 NULL, NULL },
57 #endif
58
59 /* DB_ENV->open and DB->open */
60 #if defined(WITH_DB) && defined(DB_AUTO_COMMIT)
61 { "auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_AUTO_COMMIT,
62 NULL, NULL },
63 #endif
64 #if defined(WITH_DB) && defined(DB_CREATE)
65 { "create", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_CREATE,
66 NULL, NULL },
67 #endif
68 #if defined(WITH_DB) && defined(DB_MULTIVERSION)
69 { "multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION,
70 NULL, NULL },
71 #endif
72 #if defined(WITH_DB) && defined(DB_NOMMAP)
73 { "nommap", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP,
74 NULL, NULL },
75 #endif
76 #if defined(WITH_DB) && defined(DB_THREAD)
77 { "thread", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_THREAD,
78 NULL, NULL },
79 #endif
80
81 #if defined(WITH_DB) && defined(DB_FORCE)
82 { "force", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE,
83 NULL, NULL },
84 #endif
85
86 /* DB_ENV->set_flags */
87 /* DB_ENV->get_flags */
88 #if defined(WITH_DB) && defined(DB_INIT_CDB)
89 { "cdb", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB,
90 NULL, NULL },
91 #endif
92 #if defined(WITH_DB) && defined(DB_INIT_LOCK)
93 { "lock", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOCK,
94 NULL, NULL },
95 #endif
96 #if defined(WITH_DB) && defined(DB_INIT_LOG)
97 { "log", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOG,
98 NULL, NULL },
99 #endif
100 #if defined(WITH_DB) && defined(DB_INIT_MPOOL)
101 { "mpool", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_MPOOL,
102 NULL, NULL },
103 #endif
104 #if defined(WITH_DB) && defined(DB_INIT_REP)
105 { "rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP,
106 NULL, NULL },
107 #endif
108 #if defined(WITH_DB) && defined(DB_INIT_TXN)
109 { "txn", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_TXN,
110 NULL, NULL },
111 #endif
112
113 #ifdef DYING /* XXX compatibly defined to 0 in db-4.5.20 */
114 { "joinenv", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV,
115 NULL, NULL },
116 #endif
117 #if defined(WITH_DB) && defined(DB_LOCKDOWN)
118 { "lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
119 NULL, NULL },
120 #endif
121 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_PRIVATE)
122 { "private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE,
123 NULL, NULL },
124 #endif
125 #if defined(WITH_DB) && defined(DB_RECOVER)
126 { "recover", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER,
127 NULL, NULL },
128 #endif
129 #if defined(WITH_DB) && defined(DB_RECOVER_FATAL)
130 { "recover_fatal", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER_FATAL,
131 NULL, NULL },
132 #endif
133 #if defined(WITH_DB) && defined(DB_REGISTER)
134 { "register", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_REGISTER,
135 NULL, NULL },
136 #endif
137 #if defined(WITH_DB) && defined(DB_SYSTEM_MEM)
138 { "shared", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM,
139 NULL, NULL },
140 #endif
141 #if defined(WITH_DB) && defined(DB_TXN_NOSYNC)
142 { "txn_nosync", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_TXN_NOSYNC,
143 NULL, NULL },
144 #endif
145 #if defined(WITH_DB) && defined(DB_USE_ENVIRON_ROOT)
146 { "use_environ_root", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT,
147 NULL, NULL },
148 #endif
149 #if defined(WITH_DB) && defined(DB_USE_ENVIRON)
150 { "use_environ", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON,
151 NULL, NULL },
152 #endif
153 #if defined(WITH_DB) && defined(DB_IGNORE_LEASE)
154 { "ignore_lease", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_IGNORE_LEASE,
155 NULL, NULL },
156 #endif
157
158 #if defined(WITH_DB) && defined(DB_TXN_SYNC)
159 { "txn_sync", 0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC,
160 NULL, NULL },
161 #endif
162 #if defined(WITH_DB) && defined(DB_TXN_NOWAIT)
163 { "txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT,
164 NULL, NULL },
165 #endif
166 #if defined(WITH_DB) && defined(DB_TXN_WAIT)
167 { "txn_wait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_WAIT,
168 NULL, NULL },
169 #endif
170
171 #if defined(WITH_DB) && defined(NOTYET)
172 DB_AUTO_COMMIT
173 DB_CDB_ALLDB
174 DB_DIRECT_DB
175 DB_DIRECT_LOG
176 DB_DSYNC_DB
177 DB_DSYNC_LOG
178 DB_LOG_AUTOREMOVE
179 DB_LOG_BUFFER_FULL /* ??? */
180 DB_LOG_INMEMORY
181 DB_NOLOCKING
182 DB_MULTIVERSION
183 DB_NOMMAP
184 DB_NOPANIC
185 DB_OVERWRITE
186 DB_PANIC_ENVIRONMENT
187 DB_REGION_INIT
188 DB_TIME_NOTGRANTED
189 DB_TXN_NOSYNC
190 DB_TXN_SNAPSHOT
191 DB_WRITE_NOSYNC
192 DB_YIELDCPU
193 #endif
194
195 /* DB->set_flags */
196 /* DB->get_flags */
197 #if defined(WITH_DB) && defined(NOTYET)
198 DB_CHKSUM
199 DB_ENCRYPT
200 DB_TXN_NOT_DURABLE
201
202 DB_DUP BTREE HASH
203 DB_DUPSORT BTREE HASH
204 DB_RECNUM BTREE
205 DB_REVSPLITOFF BTREE
206
207 DB_INORDER QUEUE
208 DB_RENUMBER RECNO
209 DB_SNAPSHOT RECNO
210 #endif
211
212 /* DB->open */
213 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_EXCL)
214 { "excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL,
215 NULL, NULL },
216 #endif
217 #if defined(WITH_DB) && defined(DB_FCNTL_LOCKING)
218 { "fcntl_locking",0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_FCNTL_LOCKING,
219 NULL, NULL },
220 #endif
221 #if defined(WITH_DB) && defined(DB_NO_AUTO_COMMIT) && defined(NOTYET)
222 { "noautocommit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT,
223 NULL, NULL },
224 #endif
225 #if defined(WITH_DB) && defined(DB_RDONLY)
226 { "rdonly", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY,
227 NULL, NULL },
228 #endif
229 #if defined(WITH_DB) && defined(DB_RDWRMASTER) && defined(NOTYET)
230 { "rdwrmaster", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDWRMASTER,
231 NULL, NULL },
232 #endif
233 #if defined(WITH_DB) && defined(NOTYET)
234 DB_READ_UNCOMITTED
235 #endif
236 #if defined(WITH_DB) && defined(DB_TRUNCATE)
237 { "truncate", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE,
238 NULL, NULL },
239 #endif
240 #if defined(WITH_DB) && defined(DB_WRITEOPEN)
241 { "writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN,
242 NULL, NULL },
243 #endif
244
245 #if defined(WITH_DB)
246 { "btree", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_BTREE,
247 NULL, NULL },
248 { "hash", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_HASH,
249 NULL, NULL },
250 { "recno", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_RECNO,
251 NULL, NULL },
252 { "queue", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_QUEUE,
253 NULL, NULL },
254 { "unknown", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_UNKNOWN,
255 NULL, NULL },
256 #endif
257
258 { "root", 0,POPT_ARG_STRING, &db3dbi.dbi_root, 0,
259 NULL, NULL },
260 { "home", 0,POPT_ARG_STRING, &db3dbi.dbi_home, 0,
261 NULL, NULL },
262 { "file", 0,POPT_ARG_STRING, &db3dbi.dbi_file, 0,
263 NULL, NULL },
264 { "subfile", 0,POPT_ARG_STRING, &db3dbi.dbi_subfile, 0,
265 NULL, NULL },
266 #if defined(WITH_DB)
267 { "mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0,
268 NULL, NULL },
269 #endif
270 { "perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0,
271 NULL, NULL },
272 #if defined(WITH_DB)
273 { "shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0,
274 NULL, NULL },
275 #endif
276 { "tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0,
277 NULL, NULL },
278
279 #if defined(WITH_DB)
280 { "host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
281 NULL, NULL },
282 { "server", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
283 NULL, NULL },
284 { "cl_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_cl_timeout, 0,
285 NULL, NULL },
286 { "sv_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_sv_timeout, 0,
287 NULL, NULL },
288 #endif
289
290 #if defined(WITH_DB)
291 { "verify", 0,POPT_ARG_NONE, &db3dbi.dbi_verify_on_close, 0,
292 NULL, NULL },
293 { "teardown", 0,POPT_ARG_NONE, &dbi_tear_down, 0,
294 NULL, NULL },
295 { "usecursors",0,POPT_ARG_NONE, &dbi_use_cursors, 0,
296 NULL, NULL },
297 { "usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0,
298 NULL, NULL },
299 #endif
300 { "nofsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_fsync, 0,
301 NULL, NULL },
302 #if defined(WITH_DB)
303 { "nodbsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_dbsync, 0,
304 NULL, NULL },
305 { "lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0,
306 NULL, NULL },
307 #endif
308 { "noload", 0,POPT_ARG_NONE, &db3dbi.dbi_noload, 0,
309 NULL, NULL },
310 { "temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0,
311 NULL, NULL },
312 #if defined(WITH_DB)
313 { "debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0,
314 NULL, NULL },
315 #endif
316
317 /* XXX set_alloc */
318 { "cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
319 NULL, NULL },
320 #if defined(WITH_DB)
321 /* XXX set_dup_compare */
322 /* XXX set_encrypt */
323 { "errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
324 NULL, NULL },
325 /* XXX set_feedback */
326 { "lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
327 NULL, NULL },
328 #endif
329 { "pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
330 NULL, NULL },
331
332 #if defined(WITH_DB)
333 { "region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1,
334 NULL, NULL },
335
336 { "thread_count", 0,POPT_ARG_INT, &db3dbi.dbi_thread_count, 0,
337 NULL, NULL },
338 #endif
339
340 #if defined(WITH_DB) && defined(DB_VERB_CHKPOINT)
341 { "chkpoint", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_CHKPOINT,
342 NULL, NULL },
343 #endif
344 #if defined(WITH_DB) && defined(DB_VERB_DEADLOCK)
345 { "deadlock", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_DEADLOCK,
346 NULL, NULL },
347 #endif
348 #if defined(WITH_DB) && defined(DB_VERB_RECOVERY)
349 { "recovery", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_RECOVERY,
350 NULL, NULL },
351 #endif
352 #if defined(WITH_DB) && defined(DB_VERB_REGISTER)
353 { "register", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REGISTER,
354 NULL, NULL },
355 #endif
356 #if defined(WITH_DB) && defined(DB_VERB_REPLICATION)
357 { "replication", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REPLICATION,
358 NULL, NULL },
359 #endif
360 #if defined(WITH_DB) && defined(DB_VERB_WAITSFOR)
361 { "waitsfor", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_WAITSFOR,
362 NULL, NULL },
363 #endif
364 #if defined(WITH_DB) && defined(DB_VERB_FILEOPS)
365 { "fileops", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_FILEOPS,
366 NULL, NULL },
367 #endif
368 #if defined(WITH_DB) && defined(DB_VERB_FILEOPS_ALL)
369 { "fileops_all",0,POPT_BIT_SET,&db3dbi.dbi_verbose, DB_VERB_FILEOPS_ALL,
370 NULL, NULL },
371 #endif
372 #if defined(WITH_DB)
373 { "verbose", 0,POPT_ARG_VAL, &db3dbi.dbi_verbose, -1,
374 NULL, NULL },
375 #endif
376
377 /* ==== Locking: */
378 /* DB_ENV->lock_detect */
379 /* DB_ENV->set_lk_detect */
380 /* DB_ENV->get_lk_detect */
381 #if defined(WITH_DB) && defined(DB_LOCK_DEFAULT)
382 { "lk_default",0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_DEFAULT,
383 NULL, NULL },
384 #endif
385 #if defined(WITH_DB) && defined(DB_LOCK_EXPIRE)
386 { "lk_expire", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_EXPIRE,
387 NULL, NULL },
388 #endif
389 #if defined(WITH_DB) && defined(DB_LOCK_MAXLOCKS)
390 { "lk_maxlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXLOCKS,
391 NULL, NULL },
392 #endif
393 #if defined(WITH_DB) && defined(DB_LOCK_MAXWRITE)
394 { "lk_maxwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXWRITE,
395 NULL, NULL },
396 #endif
397 #if defined(WITH_DB) && defined(DB_LOCK_MINLOCKS)
398 { "lk_minlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINLOCKS,
399 NULL, NULL },
400 #endif
401 #if defined(WITH_DB) && defined(DB_LOCK_MINWRITE)
402 { "lk_minwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINWRITE,
403 NULL, NULL },
404 #endif
405 #if defined(WITH_DB) && defined(DB_LOCK_OLDEST)
406 { "lk_oldest", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_OLDEST,
407 NULL, NULL },
408 #endif
409 #if defined(WITH_DB) && defined(DB_LOCK_RANDOM)
410 { "lk_random", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_RANDOM,
411 NULL, NULL },
412 #endif
413 #if defined(WITH_DB) && defined(DB_LOCK_YOUNGEST)
414 { "lk_youngest",0, POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_YOUNGEST,
415 NULL, NULL },
416 #endif
417
418 /* DB_ENV->lock_get */
419 /* XXX DB_ENV->set_lk_conflicts */
420 /* XXX DB_ENV->get_lk_conflicts */
421 #if defined(WITH_DB) && defined(NOTYET)
422 DB_LOCK_NOWAIT /* flags */
423
424 DB_LOCK_READ /* mode(s) */
425 DB_LOCK_WRITE
426 DB_LOCK_IWRITE
427 DB_LOCK_IREAD
428 DB_LOCK_IWR
429 #endif
430
431 #if defined(WITH_DB)
432 /* XXX DB_ENV->set_lk_max_lockers */
433 /* XXX DB_ENV->get_lk_max_lockers */
434 { "lk_max_lockers", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_lockers, 0,
435 NULL, NULL },
436 /* XXX DB_ENV->set_lk_max_locks */
437 /* XXX DB_ENV->get_lk_max_locks */
438 { "lk_max_locks", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_locks, 0,
439 NULL, NULL },
440 /* XXX DB_ENV->set_lk_max_objects */
441 /* XXX DB_ENV->get_lk_max_objects */
442 { "lk_max_objects", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_objects, 0,
443 NULL, NULL },
444 #endif
445
446 /* XXX DB_ENV->set_timeout */
447 #if defined(WITH_DB) && defined(NOTYET)
448 DB_SET_LOCK_TIMEOUT
449 DB_SET_TXN_NOW
450 DB_SET_TXN_TIMEOUT
451 #endif
452 /* XXX DB_ENV->get_timeout */
453
454 /* ==== Logging: */
455 #if defined(WITH_DB)
456 /* XXX DB_ENV->set_lg_bsize */
457 /* XXX DB_ENV->get_lg_bsize */
458 { "lg_bsize", 0,POPT_ARG_INT, &db3dbi.dbi_lg_bsize, 0,
459 NULL, NULL },
460 /* XXX DB_ENV->set_lg_dir */
461 /* XXX DB_ENV->get_lg_dir */
462 { "lg_dir", 0,POPT_ARG_STRING, &db3dbi.dbi_lg_dir, 0,
463 NULL, NULL },
464 /* XXX DB_ENV->set_lg_filemode */
465 /* XXX DB_ENV->get_lg_filemode */
466 { "lg_filemode", 0,POPT_ARG_INT, &db3dbi.dbi_lg_filemode, 0,
467 NULL, NULL },
468 /* XXX DB_ENV->set_lg_max */
469 /* XXX DB_ENV->get_lg_max */
470 { "lg_max", 0,POPT_ARG_INT, &db3dbi.dbi_lg_max, 0,
471 NULL, NULL },
472 /* XXX DB_ENV->set_lg_regionmax */
473 /* XXX DB_ENV->get_lg_regionmax */
474 { "lg_regionmax", 0,POPT_ARG_INT, &db3dbi.dbi_lg_regionmax, 0,
475 NULL, NULL },
476 #endif
477
478 /* ==== Memory pool: */
479 #if defined(WITH_DB)
480 { "mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
481 NULL, NULL },
482 /* XXX DB_ENV->set_mp_max_openfd */
483 /* XXX DB_ENV->set_mp_max_write */
484 { "mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
485 NULL, NULL },
486 { "mp_mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
487 NULL, NULL },
488 /* XXX DB_MPOOLFILE->set_clear_len */
489 /* XXX DB_MPOOLFILE->set_fileid */
490 /* XXX DB_MPOOLFILE->set_ftype */
491 /* XXX DB_MPOOLFILE->set_lsn_offset */
492 /* XXX DB_MPOOLFILE->set_maxsize */
493 /* XXX DB_MPOOLFILE->set_pgcookie */
494 /* XXX DB_MPOOLFILE->set_priority */
495 #endif
496
497 /* ==== Mutexes: */
498 #if defined(WITH_DB) && defined(NOTYET)
499 DB_MUTEX_PROCESS_ONLY mutex_alloc
500 DB_MUTEX_SELF_BLOCK mutex_alloc
501 DB_STAT_CLEAR mutex_stat*
502 #endif
503 #if defined(WITH_DB)
504 /* XXX DB_ENV->mutex_set_align */
505 /* XXX DB_ENV->mutex_get_align */
506 { "mutex_align", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_align, 0,
507 NULL, NULL },
508 /* XXX DB_ENV->mutex_set_increment */
509 /* XXX DB_ENV->mutex_get_increment */
510 { "mutex_increment", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_increment, 0,
511 NULL, NULL },
512 /* XXX DB_ENV->mutex_set_max */
513 /* XXX DB_ENV->mutex_get_max */
514 { "mutex_max", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_max, 0,
515 NULL, NULL },
516 /* XXX DB_ENV->mutex_set_tas_spins */
517 /* XXX DB_ENV->mutex_get_tas_spins */
518 { "mutex_tas_spins", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_tas_spins, 0,
519 NULL, NULL },
520 #endif
521
522 /* ==== Replication: */
523 /* XXX DB_ENV->rep_set_config */
524 /* XXX DB_ENV->rep_set_limit */
525 /* XXX DB_ENV->rep_set_nsites */
526 /* XXX DB_ENV->rep_set_priority */
527 /* XXX DB_ENV->rep_set_timeout */
528 /* XXX DB_ENV->rep_set_transport */
529
530 /* ==== Sequences: */
531 #if defined(WITH_DB)
532 /* XXX DB_SEQUENCE->set_cachesize */
533 /* XXX DB_SEQUENCE->get_cachesize */
534 { "seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
535 NULL, NULL },
536 #endif
537 /* XXX DB_SEQUENCE->set_flags */
538 /* XXX DB_SEQUENCE->get_flags */
539 #if defined(WITH_DB) && defined(DB_SEQ_DEC)
540 { "seq_dec", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
541 NULL, NULL },
542 #endif
543 #if defined(WITH_DB) && defined(DB_SEQ_INC)
544 { "seq_inc", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_INC,
545 NULL, NULL },
546 #endif
547 #if defined(WITH_DB) && defined(DB_SEQ_WRAP)
548 { "seq_wrap", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
549 NULL, NULL },
550 #endif
551 /* XXX DB_SEQUENCE->set_range */
552 /* XXX DB_SEQUENCE->get_range */
553 #if defined(WITH_DB) && defined(NOTYET) /* needs signed 64bit type */
554 { "seq_min", 0,POPT_ARG_INT, &db3dbi.dbi_seq_min, 0,
555 NULL, NULL },
556 { "seq_max", 0,POPT_ARG_INT, &db3dbi.dbi_seq_max, 0,
557 NULL, NULL },
558 #endif
559
560 /* ==== Transactions: */
561 /* XXX DB_ENV->txn_checkpoint */
562 /* XXX DB_ENV->txn_recover */
563 /* XXX DB_ENV->txn_stat */
564 /* XXX DB_ENV->set_timeout */
565 /* XXX DB_ENV->get_timeout */
566 #if defined(WITH_DB)
567 { "tx_max", 0,POPT_ARG_INT, &db3dbi.dbi_tx_max, 0,
568 NULL, NULL },
569 #endif
570 /* XXX DB_ENV->set_tx_timestamp */
571
572 /* XXX set_append_recno */
573 /* XXX set_bt_compare */
574 /* XXX set_bt_dup_compare */
575 /* XXX set_bt_minkey */
576 /* XXX set_bt_prefix */
577 #if defined(WITH_DB) && defined(DB_DUP)
578 { "bt_dup", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP,
579 NULL, NULL },
580 #endif
581 #if defined(WITH_DB) && defined(DB_DUPSORT)
582 { "bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT,
583 NULL, NULL },
584 #endif
585 #if defined(WITH_DB) && defined(DB_RECNUM)
586 { "bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
587 NULL, NULL },
588 #endif
589 #if defined(WITH_DB) && defined(DB_REVSPLITOFF)
590 { "bt_revsplitoff", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
591 NULL, NULL },
592 #endif
593
594 #if defined(WITH_DB) && defined(DB_DUP)
595 { "h_dup", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP,
596 NULL, NULL },
597 #endif
598 #if defined(WITH_DB) && defined(DB_SUPSORT)
599 { "h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT,
600 NULL, NULL },
601 #endif
602 #if defined(WITH_DB)
603 { "h_ffactor", 0,POPT_ARG_INT, &db3dbi.dbi_h_ffactor, 0,
604 NULL, NULL },
605 { "h_nelem", 0,POPT_ARG_INT, &db3dbi.dbi_h_nelem, 0,
606 NULL, NULL },
607 #endif
608
609 #if defined(WITH_DB) && defined(DB_RENUMBER)
610 { "re_renumber", 0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_RENUMBER,
611 NULL, NULL },
612 #endif
613 #if defined(WITH_DB) && defined(DB_SNAPSHOT)
614 { "re_snapshot",0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_SNAPSHOT,
615 NULL, NULL },
616 #endif
617 #if defined(WITH_DB)
618 { "re_delim", 0,POPT_ARG_INT, &db3dbi.dbi_re_delim, 0,
619 NULL, NULL },
620 { "re_len", 0,POPT_ARG_INT, &db3dbi.dbi_re_len, 0,
621 NULL, NULL },
622 { "re_pad", 0,POPT_ARG_INT, &db3dbi.dbi_re_pad, 0,
623 NULL, NULL },
624 { "re_source", 0,POPT_ARG_STRING, &db3dbi.dbi_re_source, 0,
625 NULL, NULL },
626
627 { "q_extentsize", 0,POPT_ARG_INT, &db3dbi.dbi_q_extentsize, 0,
628 NULL, NULL },
629 #endif
630
631 POPT_TABLEEND
632 };
633 /*@=compmempass =immediatetrans =exportlocal =exportheadervar =type@*/
634
635 dbiIndex db3Free(dbiIndex dbi)
636 {
637 if (dbi) {
638 dbi->dbi_root = _free(dbi->dbi_root);
639 dbi->dbi_home = _free(dbi->dbi_home);
640 dbi->dbi_file = _free(dbi->dbi_file);
641 dbi->dbi_subfile = _free(dbi->dbi_subfile);
642 dbi->dbi_tmpdir = _free(dbi->dbi_tmpdir);
643 dbi->dbi_host = _free(dbi->dbi_host);
644 dbi->dbi_errpfx = _free(dbi->dbi_errpfx);
645 dbi->dbi_re_source = _free(dbi->dbi_re_source);
646 dbi->dbi_stats = _free(dbi->dbi_stats);
647 dbi = _free(dbi);
648 }
649 return dbi;
650 }
651
652 /*@observer@*/ /*@unchecked@*/
653 static const char *db3_config_default =
654 "hash tmpdir=/var/tmp create cdb mpool mp_mmapsize=16Mb mp_size=1Mb perms=0644";
655
656 dbiIndex db3New(rpmdb rpmdb, rpmTag tag)
657 {
658 dbiIndex dbi = xcalloc(1, sizeof(*dbi));
659 char * dbOpts = rpmExpand("%{_dbi_config_", tagName(tag), "}", NULL);
660
661 if (!(dbOpts && *dbOpts && *dbOpts != '%')) {
662 dbOpts = _free(dbOpts);
663 dbOpts = rpmExpand("%{_dbi_config}", NULL);
664 if (!(dbOpts && *dbOpts && *dbOpts != '%')) {
665 dbOpts = rpmExpand(db3_config_default, NULL);
666 }
667 }
668
669 /* Parse the options for the database element(s). */
670 if (dbOpts && *dbOpts && *dbOpts != '%') {
671 char *o, *oe;
672 char *p, *pe;
673
674 memset(&db3dbi, 0, sizeof(db3dbi));
675 /*=========*/
676 for (o = dbOpts; o && *o; o = oe) {
677 struct poptOption *opt;
678 const char * tok;
679 int argInfo;
680
681 /* Skip leading white space. */
682 while (*o && xisspace((int)*o))
683 o++;
684
685 /* Find and terminate next key=value pair. Save next start point. */
686 for (oe = o; oe && *oe; oe++) {
687 if (xisspace((int)*oe))
688 /*@innerbreak@*/ break;
689 if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/'))
690 /*@innerbreak@*/ break;
691 }
692 if (oe && *oe)
693 *oe++ = '\0';
694 if (*o == '\0')
695 continue;
696
697 /* Separate key from value, save value start (if any). */
698 for (pe = o; pe && *pe && *pe != '='; pe++)
699 {};
700 p = (pe ? *pe++ = '\0', pe : NULL);
701
702 /* Skip over negation at start of token. */
703 for (tok = o; *tok == '!'; tok++)
704 {};
705
706 /* Find key in option table. */
707 for (opt = rdbOptions; opt->longName != NULL; opt++) {
708 if (strcmp(tok, opt->longName))
709 /*@innercontinue@*/ continue;
710 /*@innerbreak@*/ break;
711 }
712 if (opt->longName == NULL) {
713 rpmlog(RPMLOG_ERR,
714 _("unrecognized db option: \"%s\" ignored.\n"), o);
715 continue;
716 }
717
718 /* Toggle the flags for negated tokens, if necessary. */
719 argInfo = opt->argInfo;
720 if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2))
721 argInfo = POPT_BIT_CLR;
722
723 /* Save value in template as appropriate. */
724 switch (argInfo & POPT_ARG_MASK) {
725
726 case POPT_ARG_NONE:
727 (void) poptSaveInt((int *)opt->arg, argInfo, 1L);
728 /*@switchbreak@*/ break;
729 case POPT_ARG_VAL:
730 (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val);
731 /*@switchbreak@*/ break;
732 case POPT_ARG_STRING:
733 { const char ** t = opt->arg;
734 /*@-mods@*/
735 if (t) {
736 /*@-unqualifiedtrans@*/ /* FIX: opt->arg annotation in popt.h */
737 *t = _free(*t);
738 /*@=unqualifiedtrans@*/
739 *t = xstrdup( (p ? p : "") );
740 }
741 /*@=mods@*/
742 } /*@switchbreak@*/ break;
743
744 case POPT_ARG_INT:
745 case POPT_ARG_LONG:
746 { long aLong = strtol(p, &pe, 0);
747 if (pe) {
748 if (!xstrncasecmp(pe, "Mb", 2))
749 aLong *= 1024 * 1024;
750 else if (!xstrncasecmp(pe, "Kb", 2))
751 aLong *= 1024;
752 else if (*pe != '\0') {
753 rpmlog(RPMLOG_ERR,
754 _("%s has invalid numeric value, skipped\n"),
755 opt->longName);
756 continue;
757 }
758 }
759
760 if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
761 if (aLong == LONG_MIN || aLong == LONG_MAX) {
762 rpmlog(RPMLOG_ERR,
763 _("%s has too large or too small long value, skipped\n"),
764 opt->longName);
765 continue;
766 }
767 (void) poptSaveLong((long *)opt->arg, argInfo, aLong);
768 /*@switchbreak@*/ break;
769 } else {
770 if (aLong > INT_MAX || aLong < INT_MIN) {
771 rpmlog(RPMLOG_ERR,
772 _("%s has too large or too small integer value, skipped\n"),
773 opt->longName);
774 continue;
775 }
776 (void) poptSaveInt((int *)opt->arg, argInfo, aLong);
777 }
778 } /*@switchbreak@*/ break;
779 default:
780 /*@switchbreak@*/ break;
781 }
782 }
783 /*=========*/
784 }
785
786 dbOpts = _free(dbOpts);
787
788 /*@-assignexpose@*/
789 /*@i@*/ *dbi = db3dbi; /* structure assignment */
790 /*@=assignexpose@*/
791 memset(&db3dbi, 0, sizeof(db3dbi));
792
793 if (!(dbi->dbi_perms & 0600))
794 dbi->dbi_perms = 0644;
795 dbi->dbi_mode = rpmdb->db_mode;
796 /*@-assignexpose -newreftrans@*/ /* FIX: figger rpmdb/dbi refcounts */
797 /*@i@*/ dbi->dbi_rpmdb = rpmdb;
798 /*@=assignexpose =newreftrans@*/
799 dbi->dbi_rpmtag = tag;
800
801 /*
802 * Inverted lists have join length of 2, primary data has join length of 1.
803 */
804 /*@-sizeoftype@*/
805 switch (tag) {
806 case RPMDBI_PACKAGES:
807 case RPMDBI_DEPENDS:
808 dbi->dbi_jlen = 1 * sizeof(rpmuint32_t);
809 break;
810 default:
811 dbi->dbi_jlen = 2 * sizeof(rpmuint32_t);
812 break;
813 }
814 /*@=sizeoftype@*/
815
816 dbi->dbi_byteswapped = -1; /* -1 unknown, 0 native order, 1 alien order */
817
818 #if defined(WITH_DB)
819 if (!dbi->dbi_use_dbenv) { /* db3 dbenv is always used now. */
820 dbi->dbi_use_dbenv = 1;
821 dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
822 dbi->dbi_mmapsize = 16 * 1024 * 1024;
823 dbi->dbi_cachesize = 1 * 1024 * 1024;
824 }
825
826 if ((dbi->dbi_bt_flags | dbi->dbi_h_flags) & DB_DUP)
827 dbi->dbi_permit_dups = 1;
828 #endif
829
830 /*@-globstate@*/ /* FIX: *(rdbOptions->arg) reachable */
831 return dbi;
832 /*@=globstate@*/
833 }
834
835 const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
836 {
837 static char buf[256];
838 struct poptOption *opt;
839 char * oe;
840
841 oe = buf;
842 *oe = '\0';
843 for (opt = rdbOptions; opt->longName != NULL; opt++) {
844 if (opt->argInfo != POPT_BIT_SET)
845 continue;
846 if (print_dbenv_flags) {
847 if (!(opt->arg == &db3dbi.dbi_oeflags ||
848 opt->arg == &db3dbi.dbi_eflags))
849 continue;
850 } else {
851 if (!(opt->arg == &db3dbi.dbi_oeflags ||
852 opt->arg == &db3dbi.dbi_oflags))
853 continue;
854 }
855 if ((dbflags & opt->val) != opt->val)
856 continue;
857 if (oe != buf)
858 *oe++ = ':';
859 oe = stpcpy(oe, opt->longName);
860 dbflags &= ~opt->val;
861 }
862 if (dbflags) {
863 if (oe != buf)
864 *oe++ = ':';
865 sprintf(oe, "0x%x", (unsigned)dbflags);
866 }
867 return buf;
868 }
869
870 #endif