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