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