- generate an rpm header on the fly for imported pubkeys.
[platform/upstream/rpm.git] / rpmqv.c
1 #include "system.h"
2
3 #define _AUTOHELP
4
5 #if defined(IAM_RPM) || defined(__LCLINT__)
6 #define IAM_RPMBT
7 #define IAM_RPMDB
8 #define IAM_RPMEIU
9 #define IAM_RPMQV
10 #define IAM_RPMK
11 #endif
12
13 #include <rpmcli.h>
14 #include <rpmbuild.h>
15
16 #define POPT_NODEPS             1025
17 #define POPT_FORCE              1026
18 #define POPT_NOMD5              1027
19 #define POPT_NOSCRIPTS          1028
20
21 #ifdef  IAM_RPMBT
22 #include "build.h"
23 #define GETOPT_REBUILD          1003
24 #define GETOPT_RECOMPILE        1004
25 #endif
26
27 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
28 #include "signature.h"
29 #endif
30
31 #include "debug.h"
32
33 #define GETOPT_DBPATH           1010
34 #define GETOPT_SHOWRC           1018
35 #define GETOPT_DEFINEMACRO      1020
36 #define GETOPT_EVALMACRO        1021
37 #ifdef  NOTYET
38 #define GETOPT_RCFILE           1022
39 #endif
40
41 enum modes {
42
43     MODE_QUERY          = (1 <<  0),
44     MODE_VERIFY         = (1 <<  3),
45     MODE_QUERYTAGS      = (1 <<  9),
46 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
47
48     MODE_INSTALL        = (1 <<  1),
49     MODE_ERASE          = (1 <<  2),
50     MODE_ROLLBACK       = (1 << 14),
51 #define MODES_IE (MODE_INSTALL | MODE_ERASE | MODE_ROLLBACK)
52
53     MODE_BUILD          = (1 <<  4),
54     MODE_REBUILD        = (1 <<  5),
55     MODE_RECOMPILE      = (1 <<  8),
56     MODE_TARBUILD       = (1 << 11),
57 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
58
59     MODE_CHECKSIG       = (1 <<  6),
60     MODE_RESIGN         = (1 <<  7),
61 #define MODES_K  (MODE_CHECKSIG | MODE_RESIGN)
62
63     MODE_INITDB         = (1 << 10),
64     MODE_REBUILDDB      = (1 << 12),
65     MODE_VERIFYDB       = (1 << 13),
66 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
67
68
69     MODE_UNKNOWN        = 0
70 };
71
72 #define MODES_FOR_DBPATH        (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
73 #define MODES_FOR_NODEPS        (MODES_BT | MODES_IE | MODE_VERIFY)
74 #define MODES_FOR_TEST          (MODES_BT | MODES_IE)
75 #define MODES_FOR_ROOT          (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
76
77 /*@-exportheadervar@*/
78 /*@unchecked@*/
79 extern int _ftp_debug;
80 /*@unchecked@*/
81 extern int noLibio;
82 /*@unchecked@*/
83 extern int _rpmio_debug;
84
85 /*@-varuse@*/
86 /*@unchecked@*/
87 /*@observer@*/ extern const char * rpmNAME;
88 /*@=varuse@*/
89 /*@unchecked@*/
90 /*@observer@*/ extern const char * rpmEVR;
91 /*@-varuse@*/
92 /*@unchecked@*/
93 extern int rpmFLAGS;
94 /*@=varuse@*/
95
96 #ifdef  DYING
97 /*@unchecked@*/
98 extern struct MacroContext_s rpmCLIMacroContext;
99 #endif
100 /*@=exportheadervar@*/
101
102 /* options for all executables */
103
104 /*@unchecked@*/
105 static int help = 0;
106 /*@unchecked@*/
107 static int noUsageMsg = 0;
108 /*@unchecked@*/
109 /*@observer@*/ /*@null@*/ static const char * pipeOutput = NULL;
110 /*@unchecked@*/
111 static int quiet = 0;
112 /*@unchecked@*/
113 /*@observer@*/ /*@null@*/ static const char * rcfile = NULL;
114 /*@unchecked@*/
115 /*@observer@*/ /*@null@*/ static char * rootdir = "/";
116 /*@unchecked@*/
117 static int showrc = 0;
118 /*@unchecked@*/
119 static int showVersion = 0;
120
121 /*@unchecked@*/
122 static struct poptOption rpmAllPoptTable[] = {
123  { "version", '\0', 0, &showVersion, 0,
124         N_("print the version of rpm being used"),
125         NULL },
126  { "quiet", '\0', 0, &quiet, 0,
127         N_("provide less detailed output"), NULL},
128  { "verbose", 'v', 0, 0, 'v',
129         N_("provide more detailed output"), NULL},
130  { "define", '\0', POPT_ARG_STRING, 0, GETOPT_DEFINEMACRO,
131         N_("define macro <name> with value <body>"),
132         N_("'<name> <body>'") },
133  { "eval", '\0', POPT_ARG_STRING, 0, GETOPT_EVALMACRO,
134         N_("print macro expansion of <expr>+"),
135         N_("<expr>+") },
136  { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
137         N_("send stdout to <cmd>"),
138         N_("<cmd>") },
139  { "root", 'r', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &rootdir, 0,
140         N_("use <dir> as the top level directory"),
141         N_("<dir>") },
142  { "macros", '\0', POPT_ARG_STRING, &macrofiles, 0,
143         N_("read <file:...> instead of default macro file(s)"),
144         N_("<file:...>") },
145 #if !defined(GETOPT_RCFILE)
146  { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
147         N_("read <file:...> instead of default rpmrc file(s)"),
148         N_("<file:...>") },
149 #else
150  { "rcfile", '\0', 0, 0, GETOPT_RCFILE, 
151         N_("read <file:...> instead of default rpmrc file(s)"),
152         N_("<file:...>") },
153 #endif
154  { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
155         N_("display final rpmrc and macro configuration"),
156         NULL },
157
158 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
159  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
160         N_("disable use of libio(3) API"), NULL},
161 #endif
162  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
163         N_("debug protocol data stream"), NULL},
164  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
165         N_("debug rpmio I/O"), NULL},
166  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
167         N_("debug URL cache handling"), NULL},
168
169    POPT_TABLEEND
170 };
171
172 /* the structure describing the options we take and the defaults */
173 /*@unchecked@*/
174 static struct poptOption optionsTable[] = {
175
176  /* XXX colliding options */
177 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
178  {  NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i',                 NULL, NULL},
179  {  "nodeps", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NODEPS,       NULL, NULL},
180  {  "noscripts", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOSCRIPTS, NULL, NULL},
181  {  "nomd5", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOMD5,         NULL, NULL},
182  {  "force", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_FORCE,         NULL, NULL},
183 #endif
184
185 #ifdef  IAM_RPMQV
186  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
187         N_("Query options (with -q or --query):"),
188         NULL },
189  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
190         N_("Verify options (with -V or --verify):"),
191         NULL },
192 #endif  /* IAM_RPMQV */
193
194 #ifdef  IAM_RPMK
195  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
196         N_("Signature options:"),
197         NULL },
198 #endif  /* IAM_RPMK */
199
200 #ifdef  IAM_RPMDB
201  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
202         N_("Database options:"),
203         NULL },
204 #endif  /* IAM_RPMDB */
205
206 #ifdef  IAM_RPMBT
207  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
208         N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
209         NULL },
210 #endif  /* IAM_RPMBT */
211
212 #ifdef  IAM_RPMEIU
213  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
214         N_("Install/Upgrade/Erase options:"),
215         NULL },
216 #endif  /* IAM_RPMEIU */
217
218  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
219         N_("Common options for all rpm modes:"),
220         NULL },
221
222    POPT_AUTOALIAS
223    POPT_AUTOHELP
224    POPT_TABLEEND
225 };
226
227 #ifdef __MINT__
228 /* MiNT cannot dynamically increase the stack.  */
229 long _stksize = 64 * 1024L;
230 #endif
231
232 /*@exits@*/ static void argerror(const char * desc)
233         /*@globals __assert_program_name, fileSystem @*/
234         /*@modifies fileSystem @*/
235 {
236     fprintf(stderr, _("%s: %s\n"), __progname, desc);
237     exit(EXIT_FAILURE);
238 }
239
240 static void printVersion(void)
241         /*@globals fileSystem @*/
242         /*@modifies fileSystem @*/
243 {
244     fprintf(stdout, _("RPM version %s\n"), rpmEVR);
245 }
246
247 static void printBanner(void)
248         /*@globals fileSystem @*/
249         /*@modifies fileSystem @*/
250 {
251     (void) puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
252     (void) puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
253 }
254
255 static void printUsage(void)
256         /*@globals __assert_program_name, fileSystem @*/
257         /*@modifies fileSystem @*/
258 {
259     FILE * fp = stdout;
260     printVersion();
261     printBanner();
262     (void) puts("");
263
264     fprintf(fp, _("Usage: %s {--help}\n"), __progname);
265     fprintf(fp,   "       %s {--version}\n" , __progname);
266
267 #ifdef  IAM_RPMEIU
268 #ifdef  DYING
269 --dbpath        all
270 --ftpproxy etc  all
271 --force         alias for --replacepkgs --replacefiles
272 --includedocs   handle as option in table
273                 --erase forbids many options
274 #endif  /* DYING */
275 #endif  /* IAM_RPMEIU */
276
277 #ifdef  IAM_RPMQV
278 #ifdef  DYING   /* XXX popt glue needing --help doco. */
279 --dbpath        all
280 --ftpproxy etc  all
281 -i,--info       Q
282 -R,--requires   Q
283 -P,--provides   Q
284 --scripts       Q
285 --triggeredby   Q
286 --changelog     Q
287 --triggers      Q
288 --querytags     !V
289 --setperms      V
290 --setugids      V
291 #endif  /* DYING */
292 #endif  /* IAM_RPMQV */
293
294 }
295
296 /*@-mods@*/ /* FIX: shrug */
297 int main(int argc, const char ** argv)
298         /*@globals __assert_program_name,
299                 rpmGlobalMacroContext, rpmCLIMacroContext,
300                 fileSystem, internalState@*/
301         /*@modifies __assert_program_name,
302                 fileSystem, internalState@*/
303 {
304     enum modes bigMode = MODE_UNKNOWN;
305
306 #ifdef  IAM_RPMQV
307     QVA_t qva = &rpmQVArgs;
308 #endif
309
310 #ifdef  IAM_RPMBT
311     BTA_t ba = &rpmBTArgs;
312 #endif
313
314 #ifdef  IAM_RPMEIU
315    struct rpmInstallArguments_s * ia = &rpmIArgs;
316 #endif
317
318 #if defined(IAM_RPMDB)
319    struct rpmDatabaseArguments_s * da = &rpmDBArgs;
320 #endif
321
322 #if defined(IAM_RPMK)
323    struct rpmSignArguments_s * ka = &rpmKArgs;
324 #endif
325
326 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
327     char * passPhrase = "";
328 #endif
329
330     int arg;
331     int gotDbpath = 0;
332
333     const char * optArg;
334     pid_t pipeChild = 0;
335     poptContext optCon;
336     int ec = 0;
337     int status;
338     int p[2];
339         
340 #if HAVE_MCHECK_H && HAVE_MTRACE
341     /*@-noeffect@*/
342     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
343     /*@=noeffect@*/
344 #endif
345     setprogname(argv[0]);       /* Retrofit glibc __progname */
346
347     /* XXX glibc churn sanity */
348     if (__progname == NULL) {
349         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
350         else __progname = argv[0];
351     }
352
353     /* Set the major mode based on argv[0] */
354     /*@-nullpass@*/
355 #ifdef  IAM_RPMBT
356     if (!strcmp(__progname, "rpmb"))    bigMode = MODE_BUILD;
357     if (!strcmp(__progname, "rpmt"))    bigMode = MODE_TARBUILD;
358     if (!strcmp(__progname, "rpmbuild"))        bigMode = MODE_BUILD;
359 #endif
360 #ifdef  IAM_RPMQV
361     if (!strcmp(__progname, "rpmq"))    bigMode = MODE_QUERY;
362     if (!strcmp(__progname, "rpmv"))    bigMode = MODE_VERIFY;
363     if (!strcmp(__progname, "rpmquery"))        bigMode = MODE_QUERY;
364     if (!strcmp(__progname, "rpmverify"))       bigMode = MODE_VERIFY;
365 #endif
366 #ifdef  RPMEIU
367     if (!strcmp(__progname, "rpme"))    bigMode = MODE_ERASE;
368     if (!strcmp(__progname, "rpmi"))    bigMode = MODE_INSTALL;
369     if (!strcmp(__progname, "rpmu"))    bigMode = MODE_INSTALL;
370 #endif
371     /*@=nullpass@*/
372
373     /* set the defaults for the various command line options */
374     _ftp_debug = 0;
375
376 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
377     noLibio = 0;
378 #else
379     noLibio = 1;
380 #endif
381     _rpmio_debug = 0;
382
383     /* XXX Eliminate query linkage loop */
384     specedit = 0;
385     /*@-type@*/ /* FIX: casts? */
386     parseSpecVec = parseSpec;
387     freeSpecVec = freeSpec;
388     /*@=type@*/
389
390     /* set up the correct locale */
391     (void) setlocale(LC_ALL, "" );
392
393 #ifdef  __LCLINT__
394 #define LOCALEDIR       "/usr/share/locale"
395 #endif
396     bindtextdomain(PACKAGE, LOCALEDIR);
397     textdomain(PACKAGE);
398
399     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
400
401     /* Make a first pass through the arguments, looking for --rcfile */
402     /* We need to handle that before dealing with the rest of the arguments. */
403     /*@-nullpass -temptrans@*/
404     optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
405     /*@=nullpass =temptrans@*/
406     (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
407     (void) poptReadDefaultConfig(optCon, 1);
408     poptSetExecPath(optCon, RPMCONFIGDIR, 1);
409
410     /* reading rcfile early makes it easy to override */
411     /* XXX only --rcfile (and --showrc) need this pre-parse */
412
413     while ((arg = poptGetNextOpt(optCon)) > 0) {
414         switch(arg) {
415         case 'v':
416             rpmIncreaseVerbosity();     /* XXX silly use by showrc */
417             /*@switchbreak@*/ break;
418         default:
419             /*@switchbreak@*/ break;
420       }
421     }
422
423     if (rpmReadConfigFiles(rcfile, NULL))  
424         exit(EXIT_FAILURE);
425
426     if (showrc) {
427         (void) rpmShowRC(stdout);
428         exit(EXIT_SUCCESS);
429     }
430
431     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
432
433     poptResetContext(optCon);
434
435 #ifdef  IAM_RPMQV
436     qva->qva_queryFormat = _free(qva->qva_queryFormat);
437     memset(qva, 0, sizeof(*qva));
438     qva->qva_source = RPMQV_PACKAGE;
439     qva->qva_fflags = RPMFILE_ALL;
440     qva->qva_mode = ' ';
441     qva->qva_char = ' ';
442 #endif
443
444 #ifdef  IAM_RPMBT
445     ba->buildRootOverride = _free(ba->buildRootOverride);
446     ba->targets = _free(ba->targets);
447     memset(ba, 0, sizeof(*ba));
448     ba->buildMode = ' ';
449     ba->buildChar = ' ';
450 #endif
451
452 #ifdef  IAM_RPMDB
453     memset(da, 0, sizeof(*da));
454 #endif
455
456 #ifdef  IAM_RPMK
457     memset(ka, 0, sizeof(*ka));
458     ka->addSign = RPMSIGN_NONE;
459     ka->checksigFlags = CHECKSIG_ALL;
460 #endif
461
462 #ifdef  IAM_RPMEIU
463     ia->relocations = _free(ia->relocations);
464     memset(ia, 0, sizeof(*ia));
465     ia->transFlags = RPMTRANS_FLAG_NONE;
466     ia->probFilter = RPMPROB_FILTER_NONE;
467     ia->installInterfaceFlags = INSTALL_NONE;
468     ia->eraseInterfaceFlags = UNINSTALL_NONE;
469 #endif
470
471     while ((arg = poptGetNextOpt(optCon)) > 0) {
472         optArg = poptGetOptArg(optCon);
473
474         switch (arg) {
475             
476         case 'v':
477             rpmIncreaseVerbosity();
478             /*@switchbreak@*/ break;
479
480 /* XXX options used in multiple rpm modes */
481 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
482         case POPT_NOMD5:
483 #ifdef  IAM_RPMQV
484             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
485                 qva->qva_flags |= VERIFY_MD5;
486             else
487 #endif
488 #ifdef  IAM_RPMK
489             if (bigMode & MODES_K)
490                 ka->checksigFlags &= ~CHECKSIG_MD5;
491             else
492 #endif
493                 /*@-ifempty@*/ ;
494             /*@switchbreak@*/ break;
495 #endif  /* IAM_RPMQV || IAM_RPMK */
496
497 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
498         case POPT_NODEPS:
499 #ifdef  IAM_RPMQV
500             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
501                 qva->qva_flags |= VERIFY_DEPS;
502             else
503 #endif
504 #ifdef  IAM_RPMEIU
505             if ((bigMode & MODES_IE) ||
506                 (ia->installInterfaceFlags &
507             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
508                 ia->noDeps = 1;
509             else
510 #endif
511 #ifdef  IAM_RPMBT
512             if ((bigMode & MODES_BT) || ba->buildMode != ' ')
513                 ba->noDeps = 1;
514             else
515 #endif
516                 /*@-ifempty@*/ ;
517             /*@switchbreak@*/ break;
518
519         case POPT_FORCE:
520 #ifdef  IAM_RPMEIU
521             if ((bigMode & MODES_IE) ||
522                 (ia->installInterfaceFlags &
523             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
524                 ia->probFilter |=
525                         ( RPMPROB_FILTER_REPLACEPKG
526                         | RPMPROB_FILTER_REPLACEOLDFILES
527                         | RPMPROB_FILTER_REPLACENEWFILES
528                         | RPMPROB_FILTER_OLDPACKAGE);
529             else
530 #endif
531 #ifdef  IAM_RPMBT
532             if ((bigMode & MODES_BT) || ba->buildMode != ' ')
533                 ba->force = 1;
534             else
535 #endif
536                 /*@-ifempty@*/ ;
537             /*@switchbreak@*/ break;
538
539         case 'i':
540 #ifdef  IAM_RPMQV
541             if (bigMode == MODE_QUERY || qva->qva_mode == 'q') {
542                 /*@-nullassign -readonlytrans@*/
543                 const char * infoCommand[] = { "--info", NULL };
544                 /*@=nullassign =readonlytrans@*/
545                 (void) poptStuffArgs(optCon, infoCommand);
546             } else
547 #endif
548 #ifdef  IAM_RPMEIU
549             if (bigMode == MODE_INSTALL ||
550                 (ia->installInterfaceFlags &
551                     (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)))
552                 /*@-ifempty@*/ ;
553             else if (bigMode == MODE_UNKNOWN) {
554                 /*@-nullassign -readonlytrans@*/
555                 const char * installCommand[] = { "--install", NULL };
556                 /*@=nullassign =readonlytrans@*/
557                 (void) poptStuffArgs(optCon, installCommand);
558             } else
559 #endif
560                 /*@-ifempty@*/ ;
561             /*@switchbreak@*/ break;
562
563         case POPT_NOSCRIPTS:
564 #ifdef  IAM_RPMQV
565             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
566                 qva->qva_flags |= VERIFY_SCRIPT;
567             else
568 #endif
569 #ifdef  IAM_RPMEIU
570             if ((bigMode & MODES_IE) ||
571                 (ia->installInterfaceFlags &
572             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
573                 ia->transFlags |= (_noTransScripts | _noTransTriggers);
574             else
575 #endif
576                 /*@-ifempty@*/ ;
577             /*@switchbreak@*/ break;
578
579 #endif  /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
580
581         case GETOPT_DEFINEMACRO:
582             if (optArg) {
583                 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
584 /*@i@*/         (void) rpmDefineMacro(rpmCLIMacroContext, optArg,RMIL_CMDLINE);
585             }
586             noUsageMsg = 1;
587             /*@switchbreak@*/ break;
588
589         case GETOPT_EVALMACRO:
590             if (optArg) {
591                 const char *val = rpmExpand(optArg, NULL);
592                 fprintf(stdout, "%s\n", val);
593                 val = _free(val);
594             }
595             noUsageMsg = 1;
596             /*@switchbreak@*/ break;
597
598 #if defined(GETOPT_RCFILE)
599         case GETOPT_RCFILE:
600             fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
601             fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
602             exit(EXIT_FAILURE);
603             /*@notreached@*/ break;
604 #endif
605
606         default:
607             fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
608             exit(EXIT_FAILURE);
609         }
610     }
611
612     if (quiet)
613         rpmSetVerbosity(RPMMESS_QUIET);
614
615     if (showVersion) printVersion();
616
617     if (arg < -1) {
618         fprintf(stderr, "%s: %s\n", 
619                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
620                 poptStrerror(arg));
621         exit(EXIT_FAILURE);
622     }
623
624 #ifdef  IAM_RPMBT
625     switch (ba->buildMode) {
626     case 'b':   bigMode = MODE_BUILD;           break;
627     case 't':   bigMode = MODE_TARBUILD;        break;
628     case 'B':   bigMode = MODE_REBUILD;         break;
629     case 'C':   bigMode = MODE_RECOMPILE;       break;
630     }
631
632     if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
633         bigMode = MODE_BUILD;
634
635     if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
636         bigMode = MODE_BUILD;
637
638     if (ba->buildRootOverride && bigMode != MODE_BUILD &&
639         bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
640         argerror("--buildroot may only be used during package builds");
641     }
642 #endif  /* IAM_RPMBT */
643     
644 #ifdef  IAM_RPMDB
645   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
646     if (da->init) {
647         if (bigMode != MODE_UNKNOWN) 
648             argerror(_("only one major mode may be specified"));
649         else
650             bigMode = MODE_INITDB;
651     } else
652     if (da->rebuild) {
653         if (bigMode != MODE_UNKNOWN) 
654             argerror(_("only one major mode may be specified"));
655         else
656             bigMode = MODE_REBUILDDB;
657     } else
658     if (da->verify) {
659         if (bigMode != MODE_UNKNOWN) 
660             argerror(_("only one major mode may be specified"));
661         else
662             bigMode = MODE_VERIFYDB;
663     }
664   }
665 #endif  /* IAM_RPMDB */
666
667 #ifdef  IAM_RPMQV
668   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
669     switch (qva->qva_mode) {
670     case 'q':   bigMode = MODE_QUERY;           break;
671     case 'V':   bigMode = MODE_VERIFY;          break;
672     case 'Q':   bigMode = MODE_QUERYTAGS;       break;
673     }
674
675     if (qva->qva_sourceCount) {
676         if (qva->qva_sourceCount > 2)
677             argerror(_("one type of query/verify may be performed at a "
678                         "time"));
679     }
680     if (qva->qva_flags && (bigMode & ~MODES_QV)) 
681         argerror(_("unexpected query flags"));
682
683     if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) 
684         argerror(_("unexpected query format"));
685
686     if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) 
687         argerror(_("unexpected query source"));
688   }
689 #endif  /* IAM_RPMQV */
690
691 #ifdef  IAM_RPMEIU
692   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
693     {   int iflags = (ia->installInterfaceFlags &
694                 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
695         int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
696
697         if (iflags & eflags)
698             argerror(_("only one major mode may be specified"));
699         else if (iflags)
700             bigMode = MODE_INSTALL;
701         else if (eflags)
702             bigMode = MODE_ERASE;
703     }
704 #endif  /* IAM_RPMQV */
705
706 #ifdef  IAM_RPMK
707   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
708         switch (ka->addSign) {
709         case RPMSIGN_NONE:
710             ka->sign = 0;
711             break;
712         case RPMSIGN_IMPORT_PUBKEY:
713         case RPMSIGN_CHK_SIGNATURE:
714             bigMode = MODE_CHECKSIG;
715             ka->sign = 0;
716             break;
717         case RPMSIGN_ADD_SIGNATURE:
718         case RPMSIGN_NEW_SIGNATURE:
719             bigMode = MODE_RESIGN;
720             ka->sign = 1;
721             break;
722         }
723   }
724 #endif  /* IAM_RPMK */
725
726     /* XXX TODO: never happens. */
727     if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
728         argerror(_("--dbpath given for operation that does not use a "
729                         "database"));
730
731 #if defined(IAM_RPMEIU)
732     if (!( bigMode == MODE_INSTALL ) &&
733 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
734         argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
735     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
736         argerror(_("files may only be relocated during package installation"));
737
738     if (ia->relocations && ia->prefix)
739         argerror(_("only one of --prefix or --relocate may be used"));
740
741     if (bigMode != MODE_INSTALL && ia->relocations)
742         argerror(_("--relocate and --excludepath may only be used when installing new packages"));
743
744     if (bigMode != MODE_INSTALL && ia->prefix)
745         argerror(_("--prefix may only be used when installing new packages"));
746
747     if (ia->prefix && ia->prefix[0] != '/') 
748         argerror(_("arguments to --prefix must begin with a /"));
749
750     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
751         argerror(_("--hash (-h) may only be specified during package "
752                         "installation"));
753
754     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
755         argerror(_("--percent may only be specified during package "
756                         "installation"));
757
758     if (bigMode != MODE_INSTALL &&
759  (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
760         argerror(_("--replacefiles may only be specified during package "
761                         "installation"));
762
763     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
764         argerror(_("--replacepkgs may only be specified during package "
765                         "installation"));
766
767     if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
768         argerror(_("--excludedocs may only be specified during package "
769                    "installation"));
770
771     if (bigMode != MODE_INSTALL && ia->incldocs)
772         argerror(_("--includedocs may only be specified during package "
773                    "installation"));
774
775     if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
776         argerror(_("only one of --excludedocs and --includedocs may be "
777                  "specified"));
778   
779     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
780         argerror(_("--ignorearch may only be specified during package "
781                    "installation"));
782
783     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
784         argerror(_("--ignoreos may only be specified during package "
785                    "installation"));
786
787     if (bigMode != MODE_INSTALL &&
788         (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
789         argerror(_("--ignoresize may only be specified during package "
790                    "installation"));
791
792     if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
793         argerror(_("--allmatches may only be specified during package "
794                    "erasure"));
795
796     if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
797         argerror(_("--allfiles may only be specified during package "
798                    "installation"));
799
800     if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
801         bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
802         argerror(_("--justdb may only be specified during package "
803                    "installation and erasure"));
804
805     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
806         (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
807         argerror(_("script disabling options may only be specified during "
808                    "package installation and erasure"));
809
810     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
811         (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
812         argerror(_("trigger disabling options may only be specified during "
813                    "package installation and erasure"));
814
815     if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
816         argerror(_("--nodeps may only be specified during package "
817                    "building, rebuilding, recompilation, installation,"
818                    "erasure, and verification"));
819
820     if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
821         argerror(_("--test may only be specified during package installation, "
822                  "erasure, and building"));
823 #endif  /* IAM_RPMEIU */
824
825     if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
826         argerror(_("--root (-r) may only be specified during "
827                  "installation, erasure, querying, and "
828                  "database rebuilds"));
829
830     if (rootdir) {
831         switch (urlIsURL(rootdir)) {
832         default:
833             if (bigMode & MODES_FOR_ROOT)
834                 break;
835             /*@fallthrough@*/
836         case URL_IS_UNKNOWN:
837             if (rootdir[0] != '/')
838                 argerror(_("arguments to --root (-r) must begin with a /"));
839             break;
840         }
841     }
842
843 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
844     if (0
845 #if defined(IAM_RPMBT)
846     || ba->sign 
847 #endif
848 #if defined(IAM_RPMK)
849     || ka->sign
850 #endif
851     )
852     /*@-branchstate@*/
853     {
854         if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
855             bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD)
856         {
857             const char ** av;
858             struct stat sb;
859             int errors = 0;
860
861             if ((av = poptGetArgs(optCon)) == NULL) {
862                 fprintf(stderr, _("no files to sign\n"));
863                 errors++;
864             } else
865             while (*av) {
866                 if (stat(*av, &sb)) {
867                     fprintf(stderr, _("cannot access file %s\n"), *av);
868                     errors++;
869                 }
870                 av++;
871             }
872
873             if (errors) {
874                 ec = errors;
875                 goto exit;
876             }
877
878             if (poptPeekArg(optCon)) {
879                 int sigTag;
880                 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
881                   case 0:
882                     break;
883                   case RPMSIGTAG_PGP:
884                     if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
885                         !rpmDetectPGPVersion(NULL)) {
886                         fprintf(stderr, _("pgp not found: "));
887                         ec = EXIT_FAILURE;
888                         goto exit;
889                     }   /*@fallthrough@*/
890                   case RPMSIGTAG_GPG:
891                     passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
892                     if (passPhrase == NULL) {
893                         fprintf(stderr, _("Pass phrase check failed\n"));
894                         ec = EXIT_FAILURE;
895                         goto exit;
896                     }
897                     fprintf(stderr, _("Pass phrase is good.\n"));
898                     passPhrase = xstrdup(passPhrase);
899                     break;
900                   default:
901                     fprintf(stderr,
902                             _("Invalid %%_signature spec in macro file.\n"));
903                     ec = EXIT_FAILURE;
904                     goto exit;
905                     /*@notreached@*/ break;
906                 }
907             }
908         } else {
909             argerror(_("--sign may only be used during package building"));
910         }
911     } else {
912         /* Make rpmLookupSignatureType() return 0 ("none") from now on */
913         (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
914     }
915     /*@=branchstate@*/
916 #endif  /* IAM_RPMBT || IAM_RPMK */
917
918     if (pipeOutput) {
919         (void) pipe(p);
920
921         if (!(pipeChild = fork())) {
922             (void) close(p[1]);
923             (void) dup2(p[0], STDIN_FILENO);
924             (void) close(p[0]);
925             (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
926             fprintf(stderr, _("exec failed\n"));
927         }
928
929         (void) close(p[0]);
930         (void) dup2(p[1], STDOUT_FILENO);
931         (void) close(p[1]);
932     }
933         
934     switch (bigMode) {
935 #ifdef  IAM_RPMDB
936     case MODE_INITDB:
937         (void) rpmdbInit(rootdir, 0644);
938         break;
939
940     case MODE_REBUILDDB:
941         ec = rpmdbRebuild(rootdir);
942         break;
943     case MODE_VERIFYDB:
944         ec = rpmdbVerify(rootdir);
945         break;
946 #endif  /* IAM_RPMDB */
947
948 #ifdef  IAM_RPMBT
949     case MODE_REBUILD:
950     case MODE_RECOMPILE:
951       { const char * pkg;
952         while (!rpmIsVerbose())
953             rpmIncreaseVerbosity();
954
955         if (!poptPeekArg(optCon))
956             argerror(_("no packages files given for rebuild"));
957
958         ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
959         if (bigMode == MODE_REBUILD) {
960             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
961             ba->buildAmount |= RPMBUILD_RMSOURCE;
962             ba->buildAmount |= RPMBUILD_RMSPEC;
963             ba->buildAmount |= RPMBUILD_CLEAN;
964             ba->buildAmount |= RPMBUILD_RMBUILD;
965         }
966
967         while ((pkg = poptGetArg(optCon))) {
968             const char * specFile = NULL;
969
970             ba->cookie = NULL;
971             ec = rpmInstallSource("", pkg, &specFile, &ba->cookie);
972             if (ec == 0) {
973                 ba->rootdir = rootdir;
974                 ba->passPhrase = passPhrase;
975                 ec = build(specFile, ba, rcfile);
976             }
977             ba->cookie = _free(ba->cookie);
978             specFile = _free(specFile);
979
980             if (ec)
981                 /*@loopbreak@*/ break;
982         }
983       } break;
984
985       case MODE_BUILD:
986       case MODE_TARBUILD:
987       { const char * pkg;
988         while (!rpmIsVerbose())
989             rpmIncreaseVerbosity();
990        
991         switch (ba->buildChar) {
992         case 'a':
993             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
994             /*@fallthrough@*/
995         case 'b':
996             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
997             ba->buildAmount |= RPMBUILD_CLEAN;
998             /*@fallthrough@*/
999         case 'i':
1000             ba->buildAmount |= RPMBUILD_INSTALL;
1001             if ((ba->buildChar == 'i') && ba->shortCircuit)
1002                 /*@innerbreak@*/ break;
1003             /*@fallthrough@*/
1004         case 'c':
1005             ba->buildAmount |= RPMBUILD_BUILD;
1006             if ((ba->buildChar == 'c') && ba->shortCircuit)
1007                 /*@innerbreak@*/ break;
1008             /*@fallthrough@*/
1009         case 'p':
1010             ba->buildAmount |= RPMBUILD_PREP;
1011             /*@innerbreak@*/ break;
1012             
1013         case 'l':
1014             ba->buildAmount |= RPMBUILD_FILECHECK;
1015             /*@innerbreak@*/ break;
1016         case 's':
1017             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
1018             /*@innerbreak@*/ break;
1019         }
1020
1021         if (!poptPeekArg(optCon)) {
1022             if (bigMode == MODE_BUILD)
1023                 argerror(_("no spec files given for build"));
1024             else
1025                 argerror(_("no tar files given for build"));
1026         }
1027
1028         while ((pkg = poptGetArg(optCon))) {
1029             ba->rootdir = rootdir;
1030             ba->passPhrase = passPhrase;
1031             ba->cookie = NULL;
1032             ec = build(pkg, ba, rcfile);
1033             if (ec)
1034                 /*@loopbreak@*/ break;
1035             rpmFreeMacros(NULL);
1036             (void) rpmReadConfigFiles(rcfile, NULL);
1037         }
1038       } break;
1039 #endif  /* IAM_RPMBT */
1040
1041 #ifdef  IAM_RPMEIU
1042     case MODE_ERASE:
1043         if (!poptPeekArg(optCon))
1044             argerror(_("no packages given for uninstall"));
1045
1046         if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
1047
1048         ec = rpmErase(rootdir, (const char **)poptGetArgs(optCon), 
1049                          ia->transFlags, ia->eraseInterfaceFlags);
1050         break;
1051
1052     case MODE_INSTALL:
1053
1054         if (!poptPeekArg(optCon))
1055             argerror(_("no packages given for install"));
1056
1057         /* RPMTRANS_FLAG_BUILD_PROBS */
1058         /* RPMTRANS_FLAG_KEEPOBSOLETE */
1059
1060         if (!ia->incldocs) {
1061             if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
1062                 ;
1063             else if (rpmExpandNumeric("%{_excludedocs}"))
1064                 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
1065         }
1066
1067         if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
1068
1069         /* we've already ensured !(!ia->prefix && !ia->relocations) */
1070         /*@-branchstate@*/
1071         if (ia->prefix) {
1072             ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
1073             ia->relocations[0].oldPath = NULL;   /* special case magic */
1074             ia->relocations[0].newPath = ia->prefix;
1075             ia->relocations[1].oldPath = NULL;
1076             ia->relocations[1].newPath = NULL;
1077         } else if (ia->relocations) {
1078             ia->relocations = xrealloc(ia->relocations, 
1079                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
1080             ia->relocations[ia->numRelocations].oldPath = NULL;
1081             ia->relocations[ia->numRelocations].newPath = NULL;
1082         }
1083         /*@=branchstate@*/
1084
1085         /*@-compdef@*/ /* FIX: ia->relocations[0].newPath undefined */
1086         ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon), 
1087                         ia->transFlags, ia->installInterfaceFlags, ia->probFilter,
1088                         ia->relocations);
1089         /*@=compdef@*/
1090         break;
1091
1092     case MODE_ROLLBACK:
1093         ia->rootdir = rootdir;
1094         ec += rpmRollback(ia, (const char **)poptGetArgs(optCon));
1095         break;
1096
1097 #endif  /* IAM_RPMEIU */
1098
1099 #ifdef  IAM_RPMQV
1100     case MODE_QUERY:
1101       { const char * pkg;
1102
1103         qva->qva_prefix = rootdir;
1104         if (qva->qva_source == RPMQV_ALL) {
1105 #ifdef  DYING
1106             if (poptPeekArg(optCon))
1107                 argerror(_("extra arguments given for query of all packages"));
1108 #else
1109             const char ** av = poptGetArgs(optCon);
1110 #endif
1111             /*@-nullpass@*/     /* FIX: av can be NULL */
1112             ec = rpmQuery(qva, RPMQV_ALL, (const char *) av);
1113             /*@=nullpass@*/
1114         } else {
1115             if (!poptPeekArg(optCon))
1116                 argerror(_("no arguments given for query"));
1117             while ((pkg = poptGetArg(optCon)))
1118                 ec += rpmQuery(qva, qva->qva_source, pkg);
1119         }
1120       } break;
1121
1122     case MODE_VERIFY:
1123       { const char * pkg;
1124         rpmVerifyFlags verifyFlags = VERIFY_ALL;
1125
1126         verifyFlags &= ~qva->qva_flags;
1127         qva->qva_flags = (rpmQueryFlags) verifyFlags;
1128         qva->qva_prefix = rootdir;
1129
1130         if (qva->qva_source == RPMQV_ALL) {
1131             if (poptPeekArg(optCon))
1132                 argerror(_("extra arguments given for verify of all packages"));
1133             ec = rpmVerify(qva, RPMQV_ALL, NULL);
1134         } else {
1135             if (!poptPeekArg(optCon))
1136                 argerror(_("no arguments given for verify"));
1137             while ((pkg = poptGetArg(optCon)))
1138                 ec += rpmVerify(qva, qva->qva_source, pkg);
1139         }
1140       } break;
1141
1142     case MODE_QUERYTAGS:
1143         if (argc != 2)
1144             argerror(_("unexpected arguments to --querytags "));
1145
1146         rpmDisplayQueryTags(stdout);
1147         break;
1148 #endif  /* IAM_RPMQV */
1149
1150 #ifdef IAM_RPMK
1151     case MODE_CHECKSIG:
1152         if (!poptPeekArg(optCon))
1153             argerror(_("no packages given for signature check"));
1154         ec = rpmCheckSig(ka, (const char **)poptGetArgs(optCon));
1155         /* XXX don't overflow single byte exit status */
1156         if (ec > 255) ec = 255;
1157         break;
1158
1159     case MODE_RESIGN:
1160         if (!poptPeekArg(optCon))
1161             argerror(_("no packages given for signing"));
1162         ka->passPhrase = passPhrase;
1163         ec = rpmReSign(ka, (const char **)poptGetArgs(optCon));
1164         /* XXX don't overflow single byte exit status */
1165         if (ec > 255) ec = 255;
1166         break;
1167 #endif  /* IAM_RPMK */
1168         
1169 #if !defined(IAM_RPMQV)
1170     case MODE_QUERY:
1171     case MODE_VERIFY:
1172     case MODE_QUERYTAGS:
1173 #endif
1174 #if !defined(IAM_RPMK)
1175     case MODE_CHECKSIG:
1176     case MODE_RESIGN:
1177 #endif
1178 #if !defined(IAM_RPMDB)
1179     case MODE_INITDB:
1180     case MODE_REBUILDDB:
1181     case MODE_VERIFYDB:
1182 #endif
1183 #if !defined(IAM_RPMBT)
1184     case MODE_BUILD:
1185     case MODE_REBUILD:
1186     case MODE_RECOMPILE:
1187     case MODE_TARBUILD:
1188 #endif
1189 #if !defined(IAM_RPMEIU)
1190     case MODE_INSTALL:
1191     case MODE_ERASE:
1192     case MODE_ROLLBACK:
1193 #endif
1194     case MODE_UNKNOWN:
1195         if (!showVersion && !help && !noUsageMsg) printUsage();
1196         break;
1197     }
1198
1199 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
1200 exit:
1201 #endif  /* IAM_RPMBT || IAM_RPMK */
1202     optCon = poptFreeContext(optCon);
1203     rpmFreeMacros(NULL);
1204 /*@i@*/ rpmFreeMacros(rpmCLIMacroContext);
1205     rpmFreeRpmrc();
1206
1207     if (pipeChild) {
1208         (void) fclose(stdout);
1209         (void) waitpid(pipeChild, &status, 0);
1210     }
1211
1212     /* keeps memory leak checkers quiet */
1213     freeNames();
1214     freeFilesystems();
1215 /*@i@*/ urlFreeCache();
1216     rpmlogClose();
1217     dbiTags = _free(dbiTags);
1218
1219 #ifdef  IAM_RPMQV
1220     qva->qva_queryFormat = _free(qva->qva_queryFormat);
1221 #endif
1222
1223 #ifdef  IAM_RPMBT
1224     ba->buildRootOverride = _free(ba->buildRootOverride);
1225     ba->targets = _free(ba->targets);
1226 #endif
1227
1228 #ifdef  IAM_RPMEIU
1229     ia->relocations = _free(ia->relocations);
1230 #endif
1231
1232 #if HAVE_MCHECK_H && HAVE_MTRACE
1233     /*@-noeffect@*/
1234     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
1235     /*@=noeffect@*/
1236 #endif
1237     /*@-globstate@*/
1238     return ec;
1239     /*@=globstate@*/
1240 }
1241 /*@=mods@*/