rpm  5.4.14
dbconfig.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include <rpmio.h>
8 #include <popt.h>
9 #include <rpmlog.h>
10 #include <rpmmacro.h>
11 
12 #include <rpmtag.h>
13 #define _RPMDB_INTERNAL
14 #include <rpmdb.h>
15 #include "debug.h"
16 
17 /*@access rpmdb@*/
18 /*@access dbiIndex@*/
19 /*@access dbiIndexSet@*/
20 
21 /*@unchecked@*/
23 
24 #if defined(WITH_DB) || defined(WITH_SQLITE)
25 
26 /*@-exportlocal -exportheadervar@*/
27 /*@unchecked@*/
28 struct _dbiIndex db3dbi;
29 /*@=exportlocal =exportheadervar@*/
30 
31 /*@-compmempass -immediatetrans -exportlocal -exportheadervar -type@*/
34 /*@unchecked@*/
35 struct poptOption rdbOptions[] = {
36  /* XXX DB_CXX_NO_EXCEPTIONS */
37 #if defined(WITH_DB) && defined(DB_CLIENT)
38  { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_CLIENT,
39  NULL, NULL },
40 #endif
41 #if defined(WITH_DB) && defined(DB_RPCCLIENT)
42  { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
43  NULL, NULL },
44  { "rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
45  NULL, NULL },
46 #endif
47 
48 /* DB_ENV->open and DB->open */
49 #if defined(DB_CREATE)
50  { "create", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_CREATE,
51  NULL, NULL },
52 #endif
53 #if defined(DB_THREAD)
54  { "thread", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_THREAD,
55  NULL, NULL },
56 #endif
57 #if defined(WITH_DB) && defined(DB_MULTIVERSION)
58  { "multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION,
59  NULL, NULL },
60 #endif
61 #if defined(WITH_DB) && defined(DB_NOMMAP)
62  { "nommap", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP,
63  NULL, NULL },
64 #endif
65 
66 #if defined(WITH_DB) && defined(DB_FORCE)
67  { "force", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE,
68  NULL, NULL },
69 #endif
70 
71 /* DB_ENV->set_flags */
72 /* DB_ENV->get_flags */
73 #if defined(WITH_DB) && defined(DB_INIT_CDB)
74  { "cdb", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB,
75  NULL, NULL },
76 #endif
77 #if defined(DB_INIT_LOCK)
78  { "lock", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOCK,
79  NULL, NULL },
80 #endif
81 #if defined(DB_INIT_LOG)
82  { "log", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOG,
83  NULL, NULL },
84 #endif
85 #if defined(DB_INIT_MPOOL)
86  { "mpool", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_MPOOL,
87  NULL, NULL },
88 #endif
89 #if defined(WITH_DB) && defined(DB_INIT_REP)
90  { "rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP,
91  NULL, NULL },
92 #endif
93 #if defined(DB_INIT_TXN)
94  { "txn", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_TXN,
95  NULL, NULL },
96 #endif
97 
98 #ifdef DYING /* XXX compatibly defined to 0 in db-4.5.20 */
99  { "joinenv", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV,
100  NULL, NULL },
101 #endif
102 #if defined(WITH_DB) && defined(DB_LOCKDOWN)
103  { "lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
104  NULL, NULL },
105 #endif
106 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_PRIVATE)
107  { "private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE,
108  NULL, NULL },
109 #endif
110 #if defined(WITH_DB) && defined(DB_RECOVER)
111  { "recover", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER,
112  NULL, NULL },
113 #endif
114 #if defined(WITH_DB) && defined(DB_RECOVER_FATAL)
115  { "recover_fatal", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER_FATAL,
116  NULL, NULL },
117 #endif
118 #if defined(WITH_DB) && defined(DB_REGISTER)
119  { "register", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_REGISTER,
120  NULL, NULL },
121 #endif
122 #if defined(WITH_DB) && defined(DB_SYSTEM_MEM)
123  { "shared", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM,
124  NULL, NULL },
125 #endif
126 #if defined(WITH_DB) && defined(DB_TXN_NOSYNC)
127  { "txn_nosync", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_TXN_NOSYNC,
128  NULL, NULL },
129 #endif
130 #if defined(WITH_DB) && defined(DB_USE_ENVIRON_ROOT)
131  { "use_environ_root", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT,
132  NULL, NULL },
133 #endif
134 #if defined(WITH_DB) && defined(DB_USE_ENVIRON)
135  { "use_environ", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON,
136  NULL, NULL },
137 #endif
138 #if defined(WITH_DB) && defined(DB_IGNORE_LEASE)
139  { "ignore_lease", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_IGNORE_LEASE,
140  NULL, NULL },
141 #endif
142 
143 #if defined(WITH_DB) && defined(DB_TXN_SYNC)
144  { "txn_sync", 0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC,
145  NULL, NULL },
146 #endif
147 #if defined(WITH_DB) && defined(DB_TXN_NOWAIT)
148  { "txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT,
149  NULL, NULL },
150 #endif
151 #if defined(WITH_DB) && defined(DB_TXN_WAIT)
152  { "txn_wait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_WAIT,
153  NULL, NULL },
154 #endif
155 
156 #if defined(WITH_DB) && defined(NOTYET)
158 DB_CDB_ALLDB
159 DB_DIRECT_DB
160 DB_DIRECT_LOG
161 DB_DSYNC_DB
162 DB_DSYNC_LOG
163 DB_LOG_AUTOREMOVE
164 DB_LOG_BUFFER_FULL /* ??? */
165 DB_LOG_INMEMORY
166 DB_NOLOCKING
167 DB_MULTIVERSION
168 DB_NOMMAP
169 DB_NOPANIC
170 DB_OVERWRITE
171 DB_PANIC_ENVIRONMENT
172 DB_REGION_INIT
173 DB_TIME_NOTGRANTED
174 DB_TXN_NOSYNC
175 DB_TXN_SNAPSHOT
176 DB_WRITE_NOSYNC
177 DB_YIELDCPU
178 #endif
179 
180 /* DB->set_flags */
181 /* DB->get_flags */
182 #if defined(WITH_DB) && defined(NOTYET)
183 DB_CHKSUM
184 DB_ENCRYPT
185 DB_TXN_NOT_DURABLE
186 
187 DB_DUP BTREE HASH
188 DB_DUPSORT BTREE HASH
189 DB_RECNUM BTREE
190 DB_REVSPLITOFF BTREE
191 
192 DB_INORDER QUEUE
193 DB_RENUMBER RECNO
194 DB_SNAPSHOT RECNO
195 #endif
196 
197 /* DB->open */
198 #if defined(WITH_DB) && defined(DB_RDONLY)
199  { "rdonly", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY,
200  NULL, NULL },
201 #endif
202 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_EXCL)
203  { "excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL,
204  NULL, NULL },
205 #endif
206 #if defined(WITH_DB) && defined(DB_TRUNCATE)
207  { "truncate", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE,
208  NULL, NULL },
209 #endif
210 #if defined(WITH_DB) && defined(DB_FCNTL_LOCKING)
211  { "fcntl_locking",0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_FCNTL_LOCKING,
212  NULL, NULL },
213 #endif
214 #if defined(DB_AUTO_COMMIT)
215  { "auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_AUTO_COMMIT,
216  NULL, NULL },
217 #endif
218 #if defined(WITH_DB) && defined(DB_NO_AUTO_COMMIT) && defined(NOTYET)
219  { "noautocommit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT,
220  NULL, NULL },
221 #endif
222 #if defined(WITH_DB) && defined(DB_RDWRMASTER) && defined(NOTYET)
223  { "rdwrmaster", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDWRMASTER,
224  NULL, NULL },
225 #endif
226 #if defined(WITH_DB) && defined(NOTYET)
227 DB_READ_UNCOMITTED
228 #endif
229 #if defined(WITH_DB) && defined(DB_WRITEOPEN)
230  { "writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN,
231  NULL, NULL },
232 #endif
233 
234  { "btree", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_BTREE,
235  NULL, NULL },
236  { "hash", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_HASH,
237  NULL, NULL },
238 #if defined(WITH_DB)
239  { "recno", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_RECNO,
240  NULL, NULL },
241  { "queue", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_QUEUE,
242  NULL, NULL },
243 #if defined(DB_HEAP)
244  { "heap", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_HEAP,
245  NULL, NULL },
246 #endif
247  { "unknown", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_UNKNOWN,
248  NULL, NULL },
249 #endif
250 
251  { "root", 0,POPT_ARG_STRING, &db3dbi.dbi_root, 0,
252  NULL, NULL },
253  { "home", 0,POPT_ARG_STRING, &db3dbi.dbi_home, 0,
254  NULL, NULL },
255  { "file", 0,POPT_ARG_STRING, &db3dbi.dbi_file, 0,
256  NULL, NULL },
257  { "subfile", 0,POPT_ARG_STRING, &db3dbi.dbi_subfile, 0,
258  NULL, NULL },
259 #if defined(WITH_DB)
260  { "mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0,
261  NULL, NULL },
262 #endif
263  { "perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0,
264  NULL, NULL },
265 #if defined(WITH_DB)
266  { "shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0,
267  NULL, NULL },
268 #endif
269  { "tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0,
270  NULL, NULL },
271 
272 #if defined(WITH_DB)
273  { "host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
274  NULL, NULL },
275  { "server", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
276  NULL, NULL },
277  { "cl_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_cl_timeout, 0,
278  NULL, NULL },
279  { "sv_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_sv_timeout, 0,
280  NULL, NULL },
281 #endif
282 
283 #if defined(WITH_DB)
284  { "usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0,
285  NULL, NULL },
286 #endif
287  { "nofsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_fsync, 0,
288  NULL, NULL },
289 #if defined(WITH_DB)
290  { "nodbsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_dbsync, 0,
291  NULL, NULL },
292  { "lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0,
293  NULL, NULL },
294 #endif
295  { "primary", 0,POPT_ARG_STRING, &db3dbi.dbi_primary, 0,
296  NULL, NULL },
297  { "foreign", 0,POPT_ARG_STRING, &db3dbi.dbi_foreign, 0,
298  NULL, NULL },
299  { "temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0,
300  NULL, NULL },
301  { "debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0,
302  NULL, NULL },
303 
304 /* XXX set_alloc */
305 #if defined(WITH_DB)
306 /* XXX set_dup_compare */
307 /* XXX set_encrypt */
308  { "errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
309  NULL, NULL },
310 /* XXX set_feedback */
311  { "lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
312  NULL, NULL },
313 #endif
314  { "pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
315  NULL, NULL },
316  { "heapsize", 0,POPT_ARG_INT, &db3dbi.dbi_heapsize, 0,
317  NULL, NULL },
318  { "heap_regionsize", 0,POPT_ARG_INT, &db3dbi.dbi_heap_regionsize, 0,
319  NULL, NULL },
320 
321 #if defined(WITH_DB)
322  { "region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1,
323  NULL, NULL },
324 #endif
325 
326  { "thread_count", 0,POPT_ARG_INT, &db3dbi.dbi_thread_count, 0,
327  NULL, NULL },
328 
329 /* ==== Locking: */
330 
331 /* ==== Logging: */
332 
333 /* ==== Memory pool: */
334 /* XXX DB_MPOOLFILE->set_clear_len */
335 /* XXX DB_MPOOLFILE->set_fileid */
336 /* XXX DB_MPOOLFILE->set_ftype */
337 /* XXX DB_MPOOLFILE->set_lsn_offset */
338 /* XXX DB_MPOOLFILE->set_maxsize */
339 /* XXX DB_MPOOLFILE->set_pgcookie */
340 /* XXX DB_MPOOLFILE->set_priority */
341 
342 /* ==== Mutexes: */
343 
344 /* ==== Replication: */
345 
346 /* ==== Sequences: */
347  { "seq_id", 0,POPT_ARG_STRING, &db3dbi.dbi_seq_id, 0,
348  NULL, NULL },
349 #if defined(WITH_DB)
350 /* XXX DB_SEQUENCE->set_cachesize */
351 /* XXX DB_SEQUENCE->get_cachesize */
352  { "seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
353  NULL, NULL },
354 #endif
355 /* XXX DB_SEQUENCE->set_flags */
356 /* XXX DB_SEQUENCE->get_flags */
357 #if defined(WITH_DB) && defined(DB_SEQ_DEC)
358  { "seq_dec", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
359  NULL, NULL },
360 #endif
361 #if defined(WITH_DB) && defined(DB_SEQ_INC)
362  { "seq_inc", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_INC,
363  NULL, NULL },
364 #endif
365 #if defined(WITH_DB) && defined(DB_SEQ_WRAP)
366  { "seq_wrap", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
367  NULL, NULL },
368 #endif
369 #if defined(WITH_DB)
370 /* XXX DB_SEQUENCE->initial_value */
371  { "seq_initial", 0,POPT_ARG_LONG, &db3dbi.dbi_seq_initial, 0,
372  NULL, NULL },
373 /* XXX DB_SEQUENCE->set_range */
374 /* XXX DB_SEQUENCE->get_range */
375  { "seq_min", 0,POPT_ARG_LONG, &db3dbi.dbi_seq_min, 0,
376  NULL, NULL },
377  { "seq_max", 0,POPT_ARG_LONG, &db3dbi.dbi_seq_max, 0,
378  NULL, NULL },
379 #endif
380 
381 /* ==== Transactions: */
382 
383 /* XXX set_append_recno */
384 /* XXX set_bt_compare */
385 /* XXX set_bt_dup_compare */
386 /* XXX set_bt_minkey */
387 /* XXX set_bt_prefix */
388 #if defined(DB_DUP)
389  { "bt_dup", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP,
390  NULL, NULL },
391 #endif
392 #if defined(DB_DUPSORT)
393  { "bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT,
394  NULL, NULL },
395 #endif
396 #if defined(WITH_DB) && defined(DB_RECNUM)
397  { "bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
398  NULL, NULL },
399 #endif
400 #if defined(WITH_DB) && defined(DB_REVSPLITOFF)
401  { "bt_revsplitoff", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
402  NULL, NULL },
403 #endif
404 
405 #if defined(DB_DUP)
406  { "h_dup", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP,
407  NULL, NULL },
408 #endif
409 #if defined(DB_DUPSORT)
410  { "h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT,
411  NULL, NULL },
412 #endif
413 #if defined(WITH_DB)
414  { "h_ffactor", 0,POPT_ARG_INT, &db3dbi.dbi_h_ffactor, 0,
415  NULL, NULL },
416  { "h_nelem", 0,POPT_ARG_INT, &db3dbi.dbi_h_nelem, 0,
417  NULL, NULL },
418 #endif
419 
420 #if defined(WITH_DB) && defined(DB_RENUMBER)
421  { "re_renumber", 0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_RENUMBER,
422  NULL, NULL },
423 #endif
424 #if defined(WITH_DB) && defined(DB_SNAPSHOT)
425  { "re_snapshot",0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_SNAPSHOT,
426  NULL, NULL },
427 #endif
428 #if defined(WITH_DB)
429  { "re_delim", 0,POPT_ARG_INT, &db3dbi.dbi_re_delim, 0,
430  NULL, NULL },
431  { "re_len", 0,POPT_ARG_INT, &db3dbi.dbi_re_len, 0,
432  NULL, NULL },
433  { "re_pad", 0,POPT_ARG_INT, &db3dbi.dbi_re_pad, 0,
434  NULL, NULL },
435  { "re_source", 0,POPT_ARG_STRING, &db3dbi.dbi_re_source, 0,
436  NULL, NULL },
437 
438  { "q_extentsize", 0,POPT_ARG_INT, &db3dbi.dbi_q_extentsize, 0,
439  NULL, NULL },
440 #endif
441 
442  POPT_TABLEEND
443 };
444 /*@=compmempass =immediatetrans =exportlocal =exportheadervar =type@*/
445 
446 static void dbiFini(void * _dbi)
447  /*@*/
448 {
449  dbiIndex dbi = (dbiIndex) _dbi;
450  if (dbi) {
451  dbi->dbi_root = _free(dbi->dbi_root);
452  dbi->dbi_home = _free(dbi->dbi_home);
453  dbi->dbi_file = _free(dbi->dbi_file);
454  dbi->dbi_subfile = _free(dbi->dbi_subfile);
455  dbi->dbi_tmpdir = _free(dbi->dbi_tmpdir);
456  dbi->dbi_bf = rpmbfFree(dbi->dbi_bf);
457  dbi->dbi_host = _free(dbi->dbi_host);
458  dbi->dbi_errpfx = _free(dbi->dbi_errpfx);
459  dbi->dbi_seq_id = _free(dbi->dbi_seq_id);
460  dbi->dbi_re_source = _free(dbi->dbi_re_source);
461  dbi->dbi_primary = _free(dbi->dbi_primary);
462  dbi->dbi_foreign = _free(dbi->dbi_foreign);
463  dbi->dbi_stats = _free(dbi->dbi_stats);
464  }
465 }
466 
467 /*@unchecked@*/ /*@only@*/ /*@null@*/
469 
470 static dbiIndex dbiGetPool(rpmioPool pool)
471 {
472  dbiIndex dbi;
473 
474  if (_dbiPool == NULL) {
475  _dbiPool = rpmioNewPool("dbi", sizeof(*dbi), -1, _dbi_debug,
476  NULL, NULL, dbiFini);
477  pool = _dbiPool;
478  }
479  return (dbiIndex) rpmioGetPool(pool, sizeof(*dbi));
480 }
481 
482 dbiIndex db3New(rpmdb rpmdb, rpmTag tag)
483 {
484  dbiIndex dbi = dbiGetPool(_dbiPool);
485  char * dbOpts = rpmExpand("%{?_dbi_config_", tagName(tag), "}", NULL);
486  char *o, *oe;
487  char *p, *pe;
488 
489  if (!(dbOpts != NULL && *dbOpts != '\0')) {
490  dbOpts = _free(dbOpts);
491  dbOpts = rpmExpand("%{?_dbi_config}", NULL);
492  }
493 assert(dbOpts != NULL && *dbOpts != '\0');
494 
495  /* Parse the options for the database element(s). */
496  memset(&db3dbi, 0, sizeof(db3dbi));
497 /*=========*/
498  for (o = dbOpts; o && *o; o = oe) {
499  struct poptOption *opt;
500  const char * tok;
501  int argInfo;
502 
503  /* Skip leading white space. */
504  while (*o && xisspace((int)*o))
505  o++;
506 
507  /* Find and terminate next key=value pair. Save next start point. */
508  for (oe = o; oe && *oe; oe++) {
509  if (xisspace((int)*oe))
510  /*@innerbreak@*/ break;
511  if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/'))
512  /*@innerbreak@*/ break;
513  }
514  if (oe && *oe)
515  *oe++ = '\0';
516  if (*o == '\0')
517  continue;
518 
519  /* Separate key from value, save value start (if any). */
520  for (pe = o; pe && *pe && *pe != '='; pe++)
521  {};
522  p = (pe ? *pe++ = '\0', pe : NULL);
523 
524  /* Skip over negation at start of token. */
525  for (tok = o; *tok == '!'; tok++)
526  {};
527 
528  /* Find key in option table. */
529  for (opt = rdbOptions; opt->longName != NULL; opt++) {
530  if (strcmp(tok, opt->longName))
531  /*@innercontinue@*/ continue;
532  /*@innerbreak@*/ break;
533  }
534  if (opt->longName == NULL) {
536  _("unrecognized db option: \"%s\" ignored.\n"), o);
537  continue;
538  }
539 
540  /* Toggle the flags for negated tokens, if necessary. */
541  argInfo = opt->argInfo;
542  if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2))
543  argInfo = POPT_BIT_CLR;
544 
545  /* Save value in template as appropriate. */
546  switch (argInfo & POPT_ARG_MASK) {
547 
548  case POPT_ARG_NONE:
549  (void) poptSaveInt((int *)opt->arg, argInfo, 1L);
550  /*@switchbreak@*/ break;
551  case POPT_ARG_VAL:
552  (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val);
553  /*@switchbreak@*/ break;
554  case POPT_ARG_STRING:
555  { const char ** t = (const char **) opt->arg;
556 /*@-mods@*/
557  if (t) {
558 /*@-unqualifiedtrans@*/ /* FIX: opt->arg annotation in popt.h */
559  *t = _free(*t);
560 /*@=unqualifiedtrans@*/
561  *t = xstrdup( (p ? p : "") );
562  }
563 /*@=mods@*/
564  } /*@switchbreak@*/ break;
565  case POPT_ARG_INT:
566  case POPT_ARG_LONG:
567  { long aLong = strtol(p, &pe, 0);
568  if (pe) {
569  if (!xstrncasecmp(pe, "Mb", 2))
570  aLong *= 1024 * 1024;
571  else if (!xstrncasecmp(pe, "Kb", 2))
572  aLong *= 1024;
573  else if (*pe != '\0') {
575  _("%s has invalid numeric value, skipped\n"),
576  opt->longName);
577  continue;
578  }
579  }
580 
581  if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
582  if (aLong == LONG_MIN || aLong == LONG_MAX) {
584  _("%s has too large or too small long value, skipped\n"),
585  opt->longName);
586  continue;
587  }
588  (void) poptSaveLong((long *)opt->arg, argInfo, aLong);
589  /*@switchbreak@*/ break;
590  } else {
591  if (aLong > INT_MAX || aLong < INT_MIN) {
593  _("%s has too large or too small integer value, skipped\n"),
594  opt->longName);
595  continue;
596  }
597  (void) poptSaveInt((int *)opt->arg, argInfo, aLong);
598  }
599  } /*@switchbreak@*/ break;
600  default:
601  /*@switchbreak@*/ break;
602  }
603  }
604 /*=========*/
605 
606  dbOpts = _free(dbOpts);
607 
608 /*@-assignexpose@*/
609  { yarnLock use = dbi->_item.use;
610  void *pool = dbi->_item.pool;
611 /*@i@*/ *dbi = db3dbi; /* structure assignment */
612  dbi->_item.use = use;
613  dbi->_item.pool = pool;
614  }
615 /*@=assignexpose@*/
616 
617  memset(&db3dbi, 0, sizeof(db3dbi));
618 
619  if (!(dbi->dbi_perms & 0600))
620  dbi->dbi_perms = 0644;
621  dbi->dbi_mode = rpmdb->db_mode;
622  /*@-assignexpose -newreftrans@*/ /* FIX: figger rpmdb/dbi refcounts */
623 /*@i@*/ dbi->dbi_rpmdb = rpmdb;
624  /*@=assignexpose =newreftrans@*/
625  dbi->dbi_rpmtag = tag;
626 
627 /*@-sizeoftype@*/
628  dbi->dbi_jlen = 1 * sizeof(rpmuint32_t);
629 /*@=sizeoftype@*/
630 
631 #if defined(WITH_DB)
632  dbi->dbi_use_dbenv = 1; /* dbenv is always used now. */
633  dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
634 #endif
635 
636  /*@-globstate@*/ /* FIX: *(rdbOptions->arg) reachable */
637  return (dbiIndex)rpmioLinkPoolItem((rpmioItem)dbi, __FUNCTION__, __FILE__, __LINE__);
638  /*@=globstate@*/
639 }
640 
641 const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
642 {
643  static char buf[256];
644  struct poptOption *opt;
645  char * oe;
646 
647  oe = buf;
648  *oe = '\0';
649  for (opt = rdbOptions; opt->longName != NULL; opt++) {
650  if (opt->argInfo != POPT_BIT_SET)
651  continue;
652  if (print_dbenv_flags) {
653  if (!(opt->arg == &db3dbi.dbi_oeflags ||
654  opt->arg == &db3dbi.dbi_eflags))
655  continue;
656  } else {
657  if (!(opt->arg == &db3dbi.dbi_oeflags ||
658  opt->arg == &db3dbi.dbi_oflags))
659  continue;
660  }
661  if ((dbflags & opt->val) != opt->val)
662  continue;
663  if (oe != buf)
664  *oe++ = ':';
665  oe = stpcpy(oe, opt->longName);
666  dbflags &= ~opt->val;
667  }
668  if (dbflags) {
669  if (oe != buf)
670  *oe++ = ':';
671  sprintf(oe, "0x%x", (unsigned)dbflags);
672  }
673  return buf;
674 }
675 
676 #endif
struct rpmdb_s * rpmdb
Database of headers and tag value indices.
Definition: rpmtypes.h:43
rpmlog(RPMLOG_ERR,"%s\n", buf)
#define DB_THREAD
Definition: db_emu.h:119
void * pool
Definition: rpmmalloc.c:44
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
rpmioItem rpmioLinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Increment a pool item refcount.
Definition: rpmmalloc.c:165
enum rpmTag_e rpmTag
Definition: rpmtag.h:468
#define DB_CREATE
Definition: db_emu.h:113
int xstrncasecmp(const char *s1, const char *s2, size_t n)
Locale insensitive strncasecmp(3).
Definition: strcasecmp.c:30
sprintf(t," (%u)",(unsigned) dig->nbytes)
Yet Another syslog(3) API clone.
memset(_r, 0, sizeof(*_r))
unsigned int rpmuint32_t
Definition: rpmiotypes.h:28
assert(key->size==sizeof(hdrNum))
#define DB_INIT_TXN
Definition: db_emu.h:117
char * p
Definition: macro.c:413
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
Definition: rpmmalloc.c:220
he tag
Definition: db3.c:1927
static int xisspace(int c)
Definition: rpmiotypes.h:446
const char * tagName(rpmTag tag)
Return tag name from value.
Definition: tagname.c:436
char * oe
Definition: macro.c:745
struct yarnLock_s * yarnLock
Definition: rpmiotypes.h:37
#define DB_INIT_LOG
Definition: db_emu.h:115
char * o
Definition: macro.c:745
#define DB_INIT_LOCK
Definition: db_emu.h:114
char * rpmExpand(const char *arg,...)
Return (malloc&#39;ed) concatenated macro expansion(s).
Definition: macro.c:3178
#define L(CS)
Definition: fnmatch.c:161
#define DB_DUPSORT
Definition: db_emu.h:121
return strcmp(ame->name, bme->name)
#define DB_PRIVATE
Definition: db_emu.h:98
char * t
Definition: rpmds.c:2716
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
Definition: rpmmalloc.c:109
#define DB_EXCL
Definition: db_emu.h:97
char * stpcpy(char *dest, const char *src)
if(__progname==NULL)
Definition: poptALL.c:683
#define DB_DUP
Definition: db_emu.h:120
#define DB_INIT_MPOOL
Definition: db_emu.h:116
dbiIndex dbi
Definition: db3.c:1886
return NULL
Definition: poptALL.c:613
#define DB_AUTO_COMMIT
Definition: db_emu.h:118
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
Definition: spec.c:737
char * buf
Parse (and execute) macro undefinition.
Definition: macro.c:703
#define _(Text)
Definition: system.h:29
Access RPM indices using Berkeley DB interface(s).
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
rpmioPool _dbiPool
Definition: poptALL.c:583
int _dbi_debug
Definition: dbconfig.c:22
struct _dbiIndex * dbiIndex
Definition: rpmdb.h:59