rpm  5.4.15
poptALL.c
Go to the documentation of this file.
1 
6 #include "system.h"
7 extern const char *__progname;
8 
9 #if defined(RPM_VENDOR_WINDRIVER)
10 const char *__usrlibrpm = USRLIBRPM;
11 const char *__etcrpm = SYSCONFIGDIR;
12 #endif
13 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
14 const char *__localedir = LOCALEDIR;
15 #endif
16 
17 #define _RPMIOB_INTERNAL
18 #include <rpmio.h>
19 #include <rpmiotypes.h>
20 #include <fts.h>
21 #include <mire.h>
22 #include <poptIO.h>
23 
24 #include <rpmjni.h>
25 #include <rpmjs.h>
26 #include <rpmruby.h>
27 
28 #include <rpmtag.h>
29 #include <rpmtypes.h>
30 #include <rpmversion.h>
31 #include <rpmmdb.h>
32 #include <rpmns.h> /* XXX rpmnsClean() */
33 
34 #include <rpmrc.h>
35 #include <fs.h> /* XXX rpmFreeFilesystems() */
36 #include <rpmcli.h>
37 
38 #include "debug.h"
39 
40 #ifdef __cplusplus
41 
42 #define QVA_ISSET(_qvaflags, _FLAG) ((_qvaflags) & (VERIFY_##_FLAG))
43 
44 #define VSF_ISSET(_vsflags, _FLAG) ((_vsflags) & (RPMVSF_##_FLAG))
45 #define VSF_SET(_vsflags, _FLAG) \
46  (*((unsigned *)&(_vsflags)) |= (RPMVSF_##_FLAG))
47 #define VSF_CLR(_vsflags, _FLAG) \
48  (*((unsigned *)&(_vsflags)) &= ~(RPMVSF_##_FLAG))
49 
50 GENfree(unsigned int *)
51 
52 #else /* __cplusplus */
53 
54 #define QVA_ISSET(_qvaflags, _FLAG) ((_qvaflags) & (VERIFY_##_FLAG))
55 
56 #define VSF_ISSET(_vsflags, _FLAG) ((_vsflags) & (RPMVSF_##_FLAG))
57 #define VSF_SET(_vsflags, _FLAG) (_vsflags) |= (RPMVSF_##_FLAG)
58 #define VSF_CLR(_vsflags, _FLAG) (_vsflags) &= ~(RPMVSF_##_FLAG)
59 
60 #endif /* __cplusplus */
61 
62 /*@unchecked@*/ /*@only@*/ /*@null@*/
63 extern unsigned int * keyids;
64 
65 #define POPT_SHOWVERSION -999
66 #define POPT_SHOWRC -998
67 #define POPT_QUERYTAGS -997
68 #define POPT_PREDEFINE -996
69 #define POPT_UNDEFINE -994
70 
71 /*@access headerTagIndices @*/ /* XXX rpmcliFini */
72 /*@access headerTagTableEntry @*/ /* XXX rpmcliFini */
73 
74 /*@unchecked@*/
75 static int _debug = 0;
76 
77 /*@-exportheadervar@*/
78 /*@unchecked@*/
79 extern int _rpmds_nopromote;
80 
81 /*@unchecked@*/
82 extern int _fps_debug;
83 
84 /*@unchecked@*/
85 extern int _fsm_debug;
86 
87 /*@unchecked@*/
88 extern int _fsm_threads;
89 
90 /*@unchecked@*/
91 extern int _hdr_debug;
92 /*@unchecked@*/
93 extern int _hdrqf_debug;
94 
95 /*@unchecked@*/
96 extern int _pkgio_debug;
97 
98 /*@unchecked@*/
99 extern int _rpmrepo_debug;
100 
101 /*@unchecked@*/
102 extern int _print_pkts;
103 
104 /*@unchecked@*/
105 extern int _psm_debug;
106 /*@unchecked@*/
107 extern rpmioPool _psmPool;
108 
109 /*@unchecked@*/
110 extern int _psm_threads;
111 
112 /*@unchecked@*/
113 extern int _rpmal_debug;
114 /*@unchecked@*/
115 extern rpmioPool _rpmalPool;
116 
117 /*@unchecked@*/
118 extern int _rpmds_debug;
119 /*@unchecked@*/
120 extern rpmioPool _rpmdsPool;
121 
122 /*@unchecked@*/
124 /*@unchecked@*/
125 extern rpmioPool _rpmfcPool;
126 
127 /*@unchecked@*/
128 extern int _rpmfi_debug;
129 /*@unchecked@*/
130 extern rpmioPool _rpmfiPool;
131 
132 /*@unchecked@*/
133 extern int _rpmgi_debug;
134 /*@unchecked@*/
135 extern rpmioPool _rpmgiPool;
136 
137 /*@unchecked@*/
138 extern int _rpmmi_debug;
139 
140 /*@unchecked@*/
141 extern int _rpmps_debug;
142 /*@unchecked@*/
143 extern rpmioPool _rpmpsPool;
144 
145 /*@unchecked@*/
146 extern int _rpmsq_debug;
147 
148 /*@unchecked@*/
149 extern int _rpmte_debug;
150 /*@unchecked@*/
151 extern rpmioPool _rpmtePool;
152 /*@unchecked@*/
153 extern rpmioPool _rpmtsiPool;
154 
155 /*@unchecked@*/
156 extern int _rpmts_debug;
157 /*@unchecked@*/
158 extern rpmioPool _rpmtsPool;
159 
160 /*@unchecked@*/
161 extern int _rpmwf_debug;
162 
163 /*@unchecked@*/
164 extern int _rpmts_macros;
165 
166 /*@unchecked@*/
167 extern int _rpmts_stats;
168 
169 /*@unchecked@*/
170 extern int _hdr_stats;
171 
172 /*@unchecked@*/
174 
175 /*@unchecked@*/ /*@null@*/
176 const char * rpmcliTargets = NULL;
177 
178 /*@unchecked@*/
179 static int rpmcliInitialized = -1;
180 
181 #ifdef WITH_LUA
182 /*@unchecked@*/
183 extern const char *rpmluaFiles;
184 #endif
185 
186 /*@-readonlytrans@*/ /* argv loading prevents observer, xstrdup needed. */
187 /*@unchecked@*/
188 static const char *rpmpoptfiles = RPMPOPTFILES;
189 /*@=readonlytrans@*/
190 
194 static void printVersion(FILE * fp)
195  /*@globals rpmEVR, fileSystem, internalState @*/
196  /*@modifies *fp, fileSystem, internalState @*/
197 {
198  fprintf(fp, _("%s (" RPM_NAME ") %s\n"), __progname, rpmEVR);
199  if (rpmIsVerbose())
200  fprintf(fp, "rpmlib 0x%08x,0x%08x,0x%08x\n", (unsigned)rpmlibVersion(),
201  (unsigned)rpmlibTimestamp(), (unsigned)rpmlibVendor());
202 }
203 
205  /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
206  h_errno, fileSystem, internalState @*/
207  /*@modifies rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
208  fileSystem, internalState @*/
209 {
210 
211  if (rpmcliInitialized < 0) {
212  char * t = NULL;
213  if (rpmcliTargets != NULL) {
214  char *te;
215  t = xstrdup(rpmcliTargets);
216  if ((te = strchr(t, ',')) != NULL)
217  *te = '\0';
218  }
219  rpmcliInitialized = rpmReadConfigFiles(NULL, t);
220  t = _free(t);
221  }
222  if (rpmcliInitialized)
223  exit(EXIT_FAILURE);
224 }
225 
226 /* ========== all-rpm-modes popt args */
227 
228 static const char * rpmcliEvalSlurp(const char * arg)
229  /*@globals rpmGlobalMacroContext @*/
230  /*@modifies rpmGlobalMacroContext @*/
231 {
232  const char * pre = "";
233  const char * post = "";
234  rpmiob iob = NULL;
235  const char * val = NULL;
236  struct stat sb;
237  int xx;
238 
239  if (!strcmp(arg, "-")) { /* Macros from stdin arg. */
240  xx = rpmiobSlurp(arg, &iob);
241  } else
242  if ((arg[0] == '/' || strchr(arg, ' ') == NULL)
243  && !Stat(arg, &sb)
244  && S_ISREG(sb.st_mode)) { /* Macros from a file arg. */
245  xx = rpmiobSlurp(arg, &iob);
246  } else { /* Macros from string arg. */
247  iob = rpmiobAppend(rpmiobNew(strlen(arg)+1), arg, 0);
248  }
249 
250  val = rpmExpand(pre, iob->b, post, NULL);
251  iob = rpmiobFree(iob);
252  return val;
253 }
254 
257 static void rpmcliAllArgCallback(poptContext con,
258  /*@unused@*/ enum poptCallbackReason reason,
259  const struct poptOption * opt, const char * arg,
260  /*@unused@*/ const void * data)
261  /*@globals pgpDigVSFlags, rpmcliTargets, rpmcliQueryFlags, rpmCLIMacroContext,
262  rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
263  /*@modifies con, pgpDigVSFlags, rpmcliTargets, rpmcliQueryFlags, rpmCLIMacroContext,
264  rpmGlobalMacroContext, fileSystem, internalState @*/
265 {
266 
267  /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
268  if (opt->arg == NULL)
269  switch (opt->val) {
270  case POPT_PREDEFINE:
271  (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
272  break;
273  case 'D':
274  { char *s, *t;
275  /* XXX Convert '-' in macro name to underscore, skip leading %. */
276  s = t = xstrdup(arg);
277  while (*t && !xisspace(*t)) {
278  if (*t == '-') *t = '_';
279  t++;
280  }
281  t = s;
282  if (*t == '%') t++;
284 /*@-type@*/
285  /* XXX adding macro to global context isn't Right Thing Todo. */
286  (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
288 /*@=type@*/
289  s = _free(s);
290  } break;
291  case POPT_UNDEFINE:
292  { char *s, *t;
293  /* XXX Convert '-' in macro name to underscore, skip leading %. */
294  s = t = xstrdup(arg);
295  while (*t && !xisspace(*t)) {
296  if (*t == '-') *t = '_';
297  t++;
298  }
299  t = s;
300  if (*t == '%') t++;
301 /*@-type@*/
303  (void) rpmUndefineMacro(NULL, t);
305 /*@=type@*/
306  s = _free(s);
307  } break;
308  case 'E':
309 assert(arg != NULL);
311  { const char * val = rpmcliEvalSlurp(arg);
312  size_t val_len = fwrite(val, strlen(val), 1, stdout);
313  if (val_len > 0 && val[val_len - 1] != '\n')
314  fprintf(stdout, "\n");
315  val = _free(val);
316  } break;
317  case POPT_SHOWVERSION:
318  printVersion(stdout);
319 /*@i@*/ con = rpmcliFini(con);
320  exit(EXIT_SUCCESS);
321  /*@notreached@*/ break;
322  case POPT_SHOWRC:
324  (void) rpmShowRC(stdout);
325 /*@i@*/ con = rpmcliFini(con);
326  exit(EXIT_SUCCESS);
327  /*@notreached@*/ break;
328  case POPT_QUERYTAGS:
329  rpmDisplayQueryTags(NULL, NULL, NULL);
330 /*@i@*/ con = rpmcliFini(con);
331  exit(EXIT_SUCCESS);
332  /*@notreached@*/ break;
334  rpmcliQueryFlags = (rpmQueryFlags)(rpmcliQueryFlags | VERIFY_DIGEST);
335 #if defined(SUPPORT_NOSIGNATURES)
336  VSF_SET(pgpDigVSFlags, NOSHA1HEADER);
337  VSF_SET(pgpDigVSFlags, NOMD5HEADER);
338  VSF_SET(pgpDigVSFlags, NOSHA1);
339  VSF_SET(pgpDigVSFlags, NOMD5);
340  VSF_CLR(pgpDigVSFlags, NEEDPAYLOAD); /* XXX needed? */
341 #endif
342  break;
343 
345  rpmcliQueryFlags = (rpmQueryFlags)(rpmcliQueryFlags | VERIFY_SIGNATURE);
346 #if defined(SUPPORT_NOSIGNATURES)
347  VSF_SET(pgpDigVSFlags, NODSAHEADER);
348  VSF_SET(pgpDigVSFlags, NORSAHEADER);
349  VSF_SET(pgpDigVSFlags, NODSA);
350  VSF_SET(pgpDigVSFlags, NORSA);
351  VSF_CLR(pgpDigVSFlags, NEEDPAYLOAD); /* XXX needed? */
352 #endif
353  break;
354 
356  rpmcliQueryFlags = (rpmQueryFlags) (rpmcliQueryFlags | VERIFY_HDRCHK);
357 #if defined(SUPPORT_NOSIGNATURES)
358  VSF_SET(pgpDigVSFlags, NOHDRCHK);
359  VSF_CLR(pgpDigVSFlags, NEEDPAYLOAD); /* XXX needed? */
360 #endif
361  break;
362 
364  if (rpmcliTargets == NULL)
365  rpmcliTargets = xstrdup(arg);
366  else {
367 /*@-modobserver @*/
368  char * t = (char *) rpmcliTargets;
369  size_t nb = strlen(t) + (sizeof(",")-1) + strlen(arg) + 1;
370 /*@i@*/ t = (char *) xrealloc(t, nb);
371  (void) stpcpy( stpcpy(t, ","), arg);
372  rpmcliTargets = t;
373 /*@=modobserver @*/
374  }
375  break;
376  }
377 }
378 
379 /*@unchecked@*/
381 
382 /*@unchecked@*/
383 struct poptOption rpmcliDepFlagsPoptTable[] = {
384  { "noaid", '\0', POPT_BIT_CLR|POPT_ARGFLAG_TOGGLE, &global_depFlags, RPMDEPS_FLAG_ADDINDEPS,
385  N_("Add packages to resolve dependencies"), NULL },
386  { "anaconda", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
388  N_("Use anaconda \"presentation order\""), NULL},
389  { "deploops", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
391  N_("Print dependency loops as warning"), NULL},
392  { "nosuggest", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE,
394  N_("Do not suggest missing dependency resolution(s)"), NULL},
395  { "noconflicts", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
397  N_("Do not check added package conflicts"), NULL},
398  { "nolinktos", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
400  N_("Ignore added package requires on symlink targets"), NULL},
401  { "noobsoletes", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
403  N_("Ignore added package obsoletes"), NULL},
404  { "noparentdirs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
406  N_("Ignore added package requires on file parent directory"), NULL},
407  { "norequires", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
409  N_("Do not check added package requires"), NULL},
410  { "noupgrade", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
412  N_("Ignore added package upgrades"), NULL},
413  POPT_TABLEEND
414 };
415 
416 /*@-bitwisesigned -compmempass @*/
417 /*@unchecked@*/
418 struct poptOption rpmcliAllPoptTable[] = {
419 /*@-type@*/ /* FIX: cast? */
420  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
421  (void *) rpmcliAllArgCallback, 0, NULL, NULL },
422 /*@=type@*/
423 
424  { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
425  N_("Debug generic operations"), NULL},
426 
427  { "predefine", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_PREDEFINE,
428  N_("Predefine MACRO with value EXPR"),
429  N_("'MACRO EXPR'") },
430 
431  { "define", 'D', POPT_ARG_STRING, NULL, 'D',
432  N_("Define MACRO with value EXPR"),
433  N_("'MACRO EXPR'") },
434  { "undefine", '\0', POPT_ARG_STRING, NULL, POPT_UNDEFINE,
435  N_("Undefine MACRO"),
436  N_("'MACRO'") },
437  { "eval", 'E', POPT_ARG_STRING, NULL, 'E',
438  N_("Print macro expansion of EXPR"),
439  N_("'EXPR'") },
440  { "macros", '\0', POPT_ARG_STRING, &rpmMacrofiles, 0,
441  N_("Read <FILE:...> instead of default file(s)"),
442  N_("<FILE:...>") },
443 #ifdef WITH_LUA
444  { "rpmlua", '\0', POPT_ARG_STRING, &rpmluaFiles, 0,
445  N_("Read <FILE:...> instead of default RPM Lua file(s)"),
446  N_("<FILE:...>") },
447 #endif
448  { "rpmpopt", '\0', POPT_ARG_STRING, NULL, 0,
449  N_("Read <FILE:...> instead of default POPT file(s)"),
450  N_("<FILE:...>") },
451 
452  { "target", '\0', POPT_ARG_STRING, NULL, RPMCLI_POPT_TARGETPLATFORM,
453  N_("Specify target platform"), N_("CPU-VENDOR-OS") },
454 
455  { "nodigest", '\0', 0, NULL, RPMCLI_POPT_NODIGEST,
456  N_("Don't verify package digest(s)"), NULL },
457  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOHDRCHK,
458  N_("Don't verify database header(s) when retrieved"), NULL },
459  { "nosignature", '\0', 0, NULL, RPMCLI_POPT_NOSIGNATURE,
460  N_("Don't verify package signature(s)"), NULL },
461 
462  { "querytags", '\0', 0, NULL, POPT_QUERYTAGS,
463  N_("Display known query tags"), NULL },
464  { "showrc", '\0', 0, NULL, POPT_SHOWRC,
465  N_("Display macro and configuration values"), NULL },
466  { "version", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_SHOWVERSION,
467  N_("Print the version"), NULL },
468 
469  { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
470  NULL, NULL},
471 
472  { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
473  N_("Debug file FingerPrintS"), NULL},
474  { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
475  N_("Debug payload File State Machine"), NULL},
476  { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
477  N_("Use threads for File State Machine"), NULL},
478  { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
479  NULL, NULL},
480  { "hdrqfdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdrqf_debug, -1,
481  NULL, NULL},
482  { "macrosused", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_macros, -1,
483  N_("Display macros used"), NULL},
484  { "pkgiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_pkgio_debug, -1,
485  NULL, NULL},
486  { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
487  N_("Display OpenPGP (RFC 2440/4880) parsing"), NULL},
488  { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
489  N_("Debug Package State Machine"), NULL},
490  { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
491  N_("Use threads for Package State Machine"), NULL},
492  { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
493  N_("Debug rpmds Dependency Set"), NULL},
494  { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
495  N_("Debug rpmfc File Classifier"), NULL},
496  { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
497  N_("Debug rpmfi File Info"), NULL},
498  { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
499  N_("Debug rpmgi Generalized Iterator"), NULL},
500  { "rpmmidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmi_debug, -1,
501  N_("Debug rpmmi Match Iterator"), NULL},
502  { "rpmnsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmns_debug, -1,
503  N_("Debug rpmns Name Space"), NULL},
504  { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
505  N_("Debug rpmps Problem Set"), NULL},
506  { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
507  N_("Debug rpmte Transaction Element"), NULL},
508  { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
509  N_("Debug rpmts Transaction Set"), NULL},
510  { "rpmwfdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmwf_debug, -1,
511  N_("Debug rpmwf Wrapper Format"), NULL},
512  { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
513  N_("Display operation statistics"), NULL},
514 
515  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
516  NULL, NULL},
517 
518  POPT_TABLEEND
519 };
520 /*@=bitwisesigned =compmempass @*/
521 
522 poptContext
523 rpmcliFini(poptContext optCon)
524  /*@globals keyids @*/
525  /*@modifies keyids @*/
526 {
527 /*@-nestedextern@*/
528  extern rpmioPool _rpmjniPool;
529  extern rpmioPool _rpmjsPool;
530  extern rpmioPool _rpmrubyPool;
531  extern rpmioPool _headerPool;
532  extern rpmioPool _rpmmiPool;
533  extern rpmioPool _dbiPool;
534 #if defined(HAVE_SQLITE3_H) /* XXX test --with-sqlite=external */
535  extern rpmioPool _scpPool;
536 #endif
537  extern rpmioPool _rpmdbPool;
538  extern rpmioPool _rpmmdbPool;
539  extern rpmioPool _rpmrepoPool;
540  extern rpmioPool _rpmwfPool;
541  extern const char * evr_tuple_order;
542  extern const char * evr_tuple_match;
543  extern miRE evr_tuple_mire;
544 /*@=nestedextern@*/
545 
546 /*@-mods@*/
547  evr_tuple_order = _free(evr_tuple_order);
548  evr_tuple_match = _free(evr_tuple_match);
549  evr_tuple_mire = mireFree(evr_tuple_mire);
550 
551 /*@-onlyunqglobaltrans@*/
552  /* Realease (and dereference) embedded interpreter global objects first. */
553  _rpmjniI = rpmjniFree(_rpmjniI);
554  _rpmjniPool = rpmioFreePool(_rpmjniPool);
556  _rpmjsPool = rpmioFreePool(_rpmjsPool);
558  _rpmrubyPool = rpmioFreePool(_rpmrubyPool);
559 
561  _rpmmdbPool = rpmioFreePool(_rpmmdbPool);
562 
563  _rpmgiPool = rpmioFreePool(_rpmgiPool);
564  _rpmmiPool = rpmioFreePool(_rpmmiPool);
565 
566  _psmPool = rpmioFreePool(_psmPool);
567  _rpmtsiPool = rpmioFreePool(_rpmtsiPool);
568 
569  _rpmtsPool = rpmioFreePool(_rpmtsPool);
570  _rpmtePool = rpmioFreePool(_rpmtePool);
571  _rpmpsPool = rpmioFreePool(_rpmpsPool);
572  _rpmalPool = rpmioFreePool(_rpmalPool);
573 
574  _rpmfcPool = rpmioFreePool(_rpmfcPool);
575 
576  rpmnsClean();
577 
578  _rpmdsPool = rpmioFreePool(_rpmdsPool);
579  _rpmfiPool = rpmioFreePool(_rpmfiPool);
580 
581  _rpmwfPool = rpmioFreePool(_rpmwfPool);
582  _rpmdbPool = rpmioFreePool(_rpmdbPool);
583  _rpmrepoPool = rpmioFreePool(_rpmrepoPool);
584 #if defined(HAVE_SQLITE3_H) /* XXX test --with-sqlite=external */
585  _scpPool = rpmioFreePool(_scpPool);
586 #endif
587  _dbiPool = rpmioFreePool(_dbiPool);
588  _headerPool = rpmioFreePool(_headerPool);
589 /*@=onlyunqglobaltrans@*/
590 /*@=mods@*/
591 
592  /* XXX this should be done in the rpmioClean() wrapper. */
593  /* keeps memory leak checkers quiet */
594  rpmFreeMacros(NULL);
596 
597  rpmFreeRpmrc(); /* XXX mireFreeAll(platpat) before rpmioFreePool. */
598 
600 /*@i@*/ rpmcliTargets = _free(rpmcliTargets);
601 
602  keyids = _free(keyids);
603 
604  tagClean(NULL); /* Free header tag indices. */
605 
606  rpmioClean(); /* XXX rpmioFreePool()'s after everything else. */
607 
608  optCon = poptFreeContext(optCon);
609 
610 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
611  /*@-noeffect@*/
612  muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
613  /*@=noeffect@*/
614 #endif
615 
616 /*@-globstate@*/
617  return NULL;
618 /*@=globstate@*/
619 }
620 
621 static inline int checkfd(const char * devnull, int fdno, int flags)
622  /*@*/
623 {
624  struct stat sb;
625  int ret = 0;
626 
627  if (fstat(fdno, &sb) == -1 && errno == EBADF)
628  ret = (open(devnull, flags) == fdno) ? 1 : 2;
629  return ret;
630 }
631 
632 #if defined(RPM_VENDOR_WINDRIVER)
633 void setRuntimeRelocPaths(void)
634 {
635  /*
636  * This is just an example of setting the values using env
637  * variables.... if they're not set, we make sure they get set
638  * for helper apps... We probably want to escape "%" in the path
639  * to avoid macro expansion.. someone might have a % in a path...
640  */
641 
642  __usrlibrpm = getenv("RPM_USRLIBRPM");
643  __etcrpm = getenv("RPM_ETCRPM");
644 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
645  __localedir = getenv("RPM_LOCALEDIR");
646 #endif
647 
648  if ( __usrlibrpm == NULL ) {
649  __usrlibrpm = USRLIBRPM ;
650  setenv("RPM_USRLIBRPM", USRLIBRPM, 0);
651  }
652 
653  if ( __etcrpm == NULL ) {
654  __etcrpm = SYSCONFIGDIR ;
655  setenv("RPM_ETCRPM", SYSCONFIGDIR, 0);
656  }
657 
658 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
659  if ( __localedir == NULL ) {
660  __localedir = LOCALEDIR ;
661  setenv("RPM_LOCALEDIR", LOCALEDIR, 0);
662  }
663 #endif
664 }
665 #endif
666 
667 /*@-globstate@*/
668 poptContext
669 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
670  /*@globals rpmpoptfiles @*/
671  /*@modifies rpmpoptfiles @*/
672 {
673  poptContext optCon;
674  int rc;
675  int xx;
676  int i;
677 
678 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
679  /*@-noeffect@*/
680  mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
681  /*@=noeffect@*/
682 #endif
683 /*@-globs -mods@*/
684  setprogname(argv[0]); /* Retrofit glibc __progname */
685 
686  /* XXX glibc churn sanity */
687  if (__progname == NULL) {
688  if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
689  else __progname = argv[0];
690  }
691 /*@=globs =mods@*/
692 
693  /* Insure that stdin/stdout/stderr are open, lest stderr end up in rpmdb. */
694  { static const char _devnull[] = "/dev/null";
695 #if defined(STDIN_FILENO)
696  (void) checkfd(_devnull, STDIN_FILENO, O_RDONLY);
697 #endif
698 #if defined(STDOUT_FILENO)
699  (void) checkfd(_devnull, STDOUT_FILENO, O_WRONLY);
700 #endif
701 #if defined(STDERR_FILENO)
702  (void) checkfd(_devnull, STDERR_FILENO, O_WRONLY);
703 #endif
704  }
705 
706 #if defined(RPM_VENDOR_WINDRIVER)
707  (void) setRuntimeRelocPaths();
708 #endif
709 
710 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
711  (void) setlocale(LC_ALL, "" );
712  (void) bindtextdomain(PACKAGE, __localedir);
713  (void) textdomain(PACKAGE);
714 #endif
715 
717 
718  if (optionsTable == NULL) {
719  /* Read rpm configuration (if not already read). */
721  return NULL;
722  }
723 
724  /* read all RPM POPT configuration files */
725  for (i = 1; i < argc; i++) {
726  if (strcmp(argv[i], "--rpmpopt") == 0 && i+1 < argc) {
727  rpmpoptfiles = argv[i+1];
728  break;
729  }
730  else if (strncmp(argv[i], "--rpmpopt=", 10) == 0) {
731  rpmpoptfiles = argv[i]+10;
732  break;
733  }
734  }
735 
736  /* XXX strip off the "lt-" prefix so that rpmpopt aliases "work". */
737 { static const char lt_[] = "lt-";
738  const char * s = __progname;
739  if (!strncmp(s, lt_, sizeof(lt_)-1))
740  s += sizeof(lt_)-1;
741 /*@-nullpass -temptrans@*/
742  optCon = poptGetContext(s, argc, (const char **)argv, optionsTable, 0);
743 /*@=nullpass =temptrans@*/
744 }
745 
746 #if defined(RPM_VENDOR_OPENPKG) /* stick-with-rpm-file-sanity-checking */ || \
747  !defined(POPT_ERROR_BADCONFIG) /* XXX POPT 1.15 retrofit */
748  { char * path_buf = xstrdup(rpmpoptfiles);
749  char *path;
750  char *path_next;
751 
752  for (path = path_buf; path != NULL && *path != '\0'; path = path_next) {
753  const char **av;
754  int ac;
755 
756  /* locate start of next path element */
757  path_next = strchr(path, ':');
758  if (path_next != NULL && *path_next == ':')
759  *path_next++ = '\0';
760  else
761  path_next = path + strlen(path);
762 
763  /* glob-expand the path element */
764  ac = 0;
765  av = NULL;
766  if ((xx = rpmGlob(path, &ac, &av)) != 0)
767  continue;
768 
769  /* work-off each resulting file from the path element */
770  for (i = 0; i < ac; i++) {
771  const char *fn = av[i];
772  if (fn[0] == '@' /* attention */) {
773  fn++;
774  if (!rpmSecuritySaneFile(fn)) {
775  rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", fn);
776  /*@innercontinue@*/ continue;
777  }
778  }
779  (void) poptReadConfigFile(optCon, fn);
780  av[i] = _free(av[i]);
781  }
782  av = _free(av);
783  }
784  path_buf = _free(path_buf);
785  }
786 #else
787  /* XXX FIXME: better error message is needed. */
788  if ((xx = poptReadConfigFiles(optCon, rpmpoptfiles)) != 0)
789  rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", rpmpoptfiles);
790 #endif
791 
792 #if defined(RPM_VENDOR_WINDRIVER)
793  { const char * poptAliasFn = rpmGetPath(__usrlibrpm, "/rpmpopt", NULL);
794  (void) poptReadConfigFile(optCon, poptAliasFn);
795  poptAliasFn = _free(poptAliasFn);
796  }
797 #endif
798 
799  /* read standard POPT configuration files */
800  /* XXX FIXME: the 2nd arg useEnv flag is UNUSED. */
801  (void) poptReadDefaultConfig(optCon, 1);
802 
803 #if defined(RPM_VENDOR_WINDRIVER)
804  { const char * poptExecPath = rpmGetPath(__usrlibrpm, NULL);
805  poptSetExecPath(optCon, poptExecPath, 1);
806  poptExecPath = _free(poptExecPath);
807  }
808 #else
809  poptSetExecPath(optCon, USRLIBRPM, 1);
810 #endif
811 
812  /* Process all options, whine if unknown. */
813  while ((rc = poptGetNextOpt(optCon)) > 0) {
814  const char * optArg = poptGetOptArg(optCon);
815 /*@-dependenttrans -observertrans@*/ /* Avoid popt memory leaks. */
816  optArg = _free(optArg);
817 /*@=dependenttrans =observertrans @*/
818  switch (rc) {
819  default:
820 /*@-nullpass@*/
821  fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
822  __progname, rc);
823 /*@=nullpass@*/
824  exit(EXIT_FAILURE);
825 
826  /*@notreached@*/ /*@switchbreak@*/ break;
827  }
828  }
829 
830  if (rc < -1) {
831 /*@-nullpass@*/
832  fprintf(stderr, "%s: %s: %s\n", __progname,
833  poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
834  poptStrerror(rc));
835 /*@=nullpass@*/
836  exit(EXIT_FAILURE);
837  }
838 
839  /* Read rpm configuration (if not already read). */
841 
842  if (_debug) {
845  }
846 
847  /* Initialize header stat collection. */
848 /*@-mods@*/
849  _hdr_stats = _rpmts_stats;
850 /*@=mods@*/
851 
852  return optCon;
853 }
854 /*@=globstate@*/
rpmioPool _scpPool
Definition: sqlite.c:475
#define RPMPOPTFILES
Definition: config.h:1156
void rpmFreeMacros(MacroContext mc)
Destroy macro context.
Definition: macro.c:3088
int _rpmns_debug
Definition: rpmns.c:44
#define POPT_SHOWVERSION
Definition: poptALL.c:65
#define setprogname(pn)
Definition: system.h:364
static int _debug
Definition: poptALL.c:75
enum rpmQueryFlags_e rpmQueryFlags
Bit(s) to control rpmQuery() operation, stored in qva_flags.
#define RPMCLI_POPT_TARGETPLATFORM
Definition: rpmcli.h:103
rpmQueryFlags rpmcliQueryFlags
Bit(s) from common command line options.
Definition: poptALL.c:173
const char * evr_tuple_match
Definition: rpmevr.c:153
struct poptOption rpmcliDepFlagsPoptTable[]
Definition: poptALL.c:383
void rpmioClean(void)
Free all memory allocated by rpmio usage.
Definition: rpmio.c:3235
void tagClean(headerTagIndices _rpmTags)
Free memory in header tag indices.
Definition: tagname.c:461
char * getenv(const char *name)
#define POPT_UNDEFINE
Definition: poptALL.c:69
#define VSF_SET(_vsflags, _FLAG)
Definition: poptALL.c:57
#define EXIT_FAILURE
rpmioPool _headerPool
Definition: header.c:161
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
rpmruby _rpmrubyI
Current (global) interpreter instance.
Definition: rpmruby.c:32
rpmjs rpmjsFree(rpmjs js)
Destroy a js interpreter.
rpmmdb rpmmdbFree(rpmmdb mdb)
Destroy a mongodb wrapper.
rpmioPool _rpmtsPool
Definition: rpmts.c:774
int rpmReadConfigFiles(const char *file, const char *target)
Read macro configuration file(s) for a target.
Definition: rpmrc.c:1095
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
Definition: macro.c:3443
int _rpmgi_debug
Definition: rpmgi.c:37
const char * rpmEVR
Definition: depends.c:46
MacroContext rpmCLIMacroContext
Definition: macro.c:129
rpmioPool _rpmjsPool
Definition: rpmjs.c:140
rpmioPool _rpmmdbPool
Definition: rpmmdb.c:35
int _fsm_debug
Definition: fsm.c:61
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
Definition: poptALL.c:418
static struct poptOption optionsTable[]
Definition: rpmqv.c:168
int setenv(const char *name, const char *value, int replace)
const char * evr_tuple_order
Definition: rpmds.c:4017
int Stat(const char *path, struct stat *st)
stat(2) clone.
Definition: rpmrpc.c:1361
Structure(s) and routine(s) used for classifying and parsing names.
int _hdrqf_debug
Definition: hdrfmt.c:69
Access mounted file system information.
int _rpmmi_debug
Definition: rpmdb.c:64
int _rpmps_debug
Definition: rpmps.c:26
int errno
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
rpmioPool _rpmtsiPool
Definition: rpmte.c:773
static void rpmlog(int code, const char *fmt,...)
Definition: rpmlog.h:299
int _psm_threads
Definition: psm.c:80
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
Definition: rpmiob.c:77
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
Definition: poptALL.c:669
#define RPMCLI_POPT_NODIGEST
Definition: rpmcli.h:100
int _fsm_threads
Definition: fsm.c:65
const char * __progname
Definition: poptIO.c:66
#define bindtextdomain(Domain, Directory)
Definition: system.h:522
rpmioPool _rpmalPool
Definition: rpmal.c:167
miRE evr_tuple_mire
Definition: rpmevr.c:155
int _rpmsq_debug
Definition: rpmsq.c:278
int rpmiobSlurp(const char *fn, rpmiob *iobp)
Definition: rpmiob.c:129
rpmmdb _rpmmdbI
Definition: rpmmdb.c:21
int _hdr_debug
Definition: header.c:40
int _rpmts_debug
Definition: rpmts.c:93
int rpmGlob(const char *patterns, int *argcPtr, const char ***argvPtr)
Return URL path(s) from a (URL prefixed) pattern glob.
Definition: macro.c:2609
rpmuint32_t rpmlibVendor(void)
Definition: rpmversion.c:21
miRE mireFree(miRE mire)
Free pattern container.
pgpVSFlags pgpDigVSFlags
Disabler bits(s) for signature/digest checking.
Definition: rpmpgp.c:1153
void rpmnsClean(void)
Clean global name space dependency sets.
Definition: depends.c:858
int _print_pkts
Definition: rpmchecksig.c:47
#define RPMCLI_POPT_NOHDRCHK
Definition: rpmcli.h:101
static const char * rpmcliEvalSlurp(const char *arg)
Definition: poptALL.c:228
static int checkfd(const char *devnull, int fdno, int flags)
Definition: poptALL.c:621
static int rpmcliInitialized
Definition: poptALL.c:179
#define N_(Text)
Definition: system.h:531
RPM pattern matching.
#define VSF_CLR(_vsflags, _FLAG)
Definition: poptALL.c:58
const char const bson * data
Definition: mongo.h:463
#define POPT_ARGFLAG_TOGGLE
Definition: poptIO.c:69
rpmioPool _rpmmiPool
Definition: rpmdb.c:1729
static int xisspace(int c)
Definition: rpmiotypes.h:555
#define POPT_QUERYTAGS
Definition: poptALL.c:67
rpmioPool _rpmdsPool
Definition: rpmds.c:191
struct miRE_s * miRE
Definition: mire.h:60
#define setlocale(Category, Locale)
Definition: system.h:513
int rpmDefineMacro(MacroContext mc, const char *macro, int level)
Define macro in context.
Definition: macro.c:2851
int _rpmfc_debug
Definition: poptALL.c:123
const char * rpmcliTargets
Definition: poptALL.c:176
const char * rpmluaFiles
int _rpmal_debug
Definition: rpmal.c:35
rpmioPool _rpmrubyPool
The pool of Ruby interpreter instances.
Definition: rpmruby.c:54
const char * rpmMacrofiles
List of macro files to read when configuring rpm.
Definition: macro.c:62
#define RPM_NAME
Definition: config.h:1165
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
Definition: macro.c:3250
void rpmFreeFilesystems(void)
Release storage used by file system usage cache.
Definition: fs.c:38
int _rpmwf_debug
Definition: rpmwf.c:18
Embedded Ruby interpreter.
#define rpmSetVerbosity(_lvl)
Definition: rpmcb.h:13
const char const char int arg
Definition: mongo.h:777
#define SYSCONFIGDIR
Definition: config.h:1248
rpmuint32_t rpmlibVersion(void)
Definition: rpmversion.c:11
rpmioPool _rpmfcPool
Definition: rpmfc.c:2229
rpmioPool _rpmwfPool
Definition: rpmwf.c:214
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
Definition: rpmiob.c:44
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
#define USRLIBRPM
Definition: config.h:1297
int _rpmts_stats
Definition: rpmts.c:96
rpmuint32_t rpmlibTimestamp(void)
Definition: rpmversion.c:16
int _rpmte_debug
Definition: rpmte.c:26
rpmruby rpmrubyFree(rpmruby ruby)
Destroys a Ruby interpreter instance.
unsigned int * keyids
Definition: package.c:32
int global_depFlags
Definition: poptALL.c:380
int _rpmrepo_debug
Definition: rpmrepo.c:66
const char const int i
Definition: bson.h:778
#define RPMCLI_POPT_NOSIGNATURE
Definition: rpmcli.h:99
rpmioPool _rpmpsPool
Definition: rpmps.c:45
rpmioPool _rpmfiPool
Definition: rpmfi.c:1357
int _fps_debug
Definition: transaction.c:232
char * stpcpy(char *dest, const char *src)
void rpmcliConfigured(void)
Make sure that rpm configuration has been read.
Definition: poptALL.c:204
rpmioPool _psmPool
Definition: psm.c:1832
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:60
int rpmShowRC(FILE *fp)
Display current rpmrc (and macro) configuration.
Definition: rpmrc.c:1145
int _hdr_stats
Global header stats enabler.
Definition: header.c:84
rpmioPool _rpmdbPool
Definition: rpmdb.c:773
void rpmDisplayQueryTags(FILE *fp, headerTagTableEntry _rpmTagTable, headerSprintfExtension _rpmHeaderFormats)
Display list of tags that can be used in –queryformat.
Definition: hdrfmt.c:5282
#define LOCALEDIR
Definition: config.h:1100
int _rpmds_debug
Definition: rpmds.c:123
int rpmSecuritySaneFile(const char *filename)
Check whether configuration file is moderately secure to load.
Definition: macro.c:2586
static const char * rpmpoptfiles
Definition: poptALL.c:188
#define POPT_SHOWRC
Definition: poptALL.c:66
#define rpmIsVerbose()
Definition: rpmcb.h:21
#define textdomain(Domain)
Definition: system.h:524
int _rpmds_nopromote
Definition: rpmds.c:126
int _psm_debug
Definition: psm.c:78
int _rpmts_macros
Definition: rpmts.c:99
#define _(Text)
Definition: system.h:29
#define RMIL_CMDLINE
Definition: rpmmacro.h:66
#define PACKAGE
Definition: config.h:1123
struct poptOption rpmioAllPoptTable[]
Popt option table for options shared by all modes and executables.
Definition: poptIO.c:564
rpmjs _rpmjsI
Definition: rpmjs.c:80
int _rpmfi_debug
Definition: rpmfi.c:67
rpmioPool _rpmgiPool
Definition: rpmgi.c:525
static void printVersion(FILE *fp)
Display rpm version.
Definition: poptALL.c:194
int _pkgio_debug
Definition: pkgio.c:55
static void rpmcliAllArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Definition: poptALL.c:257
#define POPT_PREDEFINE
Definition: poptALL.c:68
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
Definition: poptALL.c:523
#define xrealloc
Definition: system.h:35
rpmioPool _rpmrepoPool
Definition: rpmrepo.c:1884
void rpmFreeRpmrc(void)
Definition: rpmrc.c:1006
rpmioPool _rpmtePool
Definition: rpmte.c:227
rpmioPool rpmioFreePool(rpmioPool pool)
Reclaim memory pool items.
Definition: rpmmalloc.c:72
int rpmUndefineMacro(MacroContext mc, const char *macro)
Undefine macro in context.
Definition: macro.c:2865
#define rpmIncreaseVerbosity()
Definition: rpmcb.h:15