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