- use rpmdb-redhat to suggest dependency resolution(s).
[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 #if !defined(__GLIBC__) && !defined(__LCLINT__)
282 int main(int argc, const char ** argv, /*@unused@*/ char ** envp)
283 #else
284 int main(int argc, const char ** argv)
285 #endif
286         /*@globals __assert_program_name, rpmEVR, RPMVERSION,
287                 rpmGlobalMacroContext, rpmCLIMacroContext,
288                 fileSystem, internalState@*/
289         /*@modifies __assert_program_name,
290                 fileSystem, internalState@*/
291 {
292     rpmTransactionSet ts = NULL;
293     enum modes bigMode = MODE_UNKNOWN;
294
295 #ifdef  IAM_RPMQV
296     QVA_t qva = &rpmQVKArgs;
297 #endif
298
299 #ifdef  IAM_RPMBT
300     BTA_t ba = &rpmBTArgs;
301 #endif
302
303 #ifdef  IAM_RPMEIU
304    struct rpmInstallArguments_s * ia = &rpmIArgs;
305 #endif
306
307 #if defined(IAM_RPMDB)
308    struct rpmDatabaseArguments_s * da = &rpmDBArgs;
309 #endif
310
311 #if defined(IAM_RPMK)
312    QVA_t ka = &rpmQVKArgs;
313 #endif
314
315 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
316     char * passPhrase = "";
317 #endif
318
319     int arg;
320     int gotDbpath = 0;
321
322     const char * optArg;
323     pid_t pipeChild = 0;
324     poptContext optCon;
325     int ec = 0;
326     int status;
327     int p[2];
328         
329 #if HAVE_MCHECK_H && HAVE_MTRACE
330     /*@-noeffect@*/
331     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
332     /*@=noeffect@*/
333 #endif
334     setprogname(argv[0]);       /* Retrofit glibc __progname */
335
336 #if !defined(__GLIBC__) && !defined(__LCLINT__)
337     environ = envp;
338 #endif  
339
340     /* XXX glibc churn sanity */
341     if (__progname == NULL) {
342         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
343         else __progname = argv[0];
344     }
345
346     /* Set the major mode based on argv[0] */
347     /*@-nullpass@*/
348 #ifdef  IAM_RPMBT
349     if (!strcmp(__progname, "rpmb"))    bigMode = MODE_BUILD;
350     if (!strcmp(__progname, "rpmt"))    bigMode = MODE_TARBUILD;
351     if (!strcmp(__progname, "rpmbuild"))        bigMode = MODE_BUILD;
352 #endif
353 #ifdef  IAM_RPMQV
354     if (!strcmp(__progname, "rpmq"))    bigMode = MODE_QUERY;
355     if (!strcmp(__progname, "rpmv"))    bigMode = MODE_VERIFY;
356     if (!strcmp(__progname, "rpmquery"))        bigMode = MODE_QUERY;
357     if (!strcmp(__progname, "rpmverify"))       bigMode = MODE_VERIFY;
358 #endif
359 #ifdef  RPMEIU
360     if (!strcmp(__progname, "rpme"))    bigMode = MODE_ERASE;
361     if (!strcmp(__progname, "rpmi"))    bigMode = MODE_INSTALL;
362     if (!strcmp(__progname, "rpmu"))    bigMode = MODE_INSTALL;
363 #endif
364     /*@=nullpass@*/
365
366     /* set the defaults for the various command line options */
367     _ftp_debug = 0;
368
369 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
370     noLibio = 0;
371 #else
372     noLibio = 1;
373 #endif
374     _rpmio_debug = 0;
375
376     /* XXX Eliminate query linkage loop */
377     specedit = 0;
378     /*@-type@*/ /* FIX: casts? */
379     parseSpecVec = parseSpec;
380     freeSpecVec = freeSpec;
381     /*@=type@*/
382
383     /* set up the correct locale */
384     (void) setlocale(LC_ALL, "" );
385
386 #ifdef  __LCLINT__
387 #define LOCALEDIR       "/usr/share/locale"
388 #endif
389     bindtextdomain(PACKAGE, LOCALEDIR);
390     textdomain(PACKAGE);
391
392     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
393
394     /* Make a first pass through the arguments, looking for --rcfile */
395     /* We need to handle that before dealing with the rest of the arguments. */
396     /*@-nullpass -temptrans@*/
397     optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
398     /*@=nullpass =temptrans@*/
399     (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
400     (void) poptReadDefaultConfig(optCon, 1);
401     poptSetExecPath(optCon, RPMCONFIGDIR, 1);
402
403     /* reading rcfile early makes it easy to override */
404     /* XXX only --rcfile (and --showrc) need this pre-parse */
405
406     while ((arg = poptGetNextOpt(optCon)) > 0) {
407         switch(arg) {
408         case 'v':
409             rpmIncreaseVerbosity();     /* XXX silly use by showrc */
410             /*@switchbreak@*/ break;
411         default:
412             /*@switchbreak@*/ break;
413       }
414     }
415
416     if (rpmReadConfigFiles(rcfile, NULL))  
417         exit(EXIT_FAILURE);
418
419     if (showrc) {
420         (void) rpmShowRC(stdout);
421         exit(EXIT_SUCCESS);
422     }
423
424     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
425
426     poptResetContext(optCon);
427
428 #ifdef  IAM_RPMQV
429     qva->qva_queryFormat = _free(qva->qva_queryFormat);
430     memset(qva, 0, sizeof(*qva));
431     qva->qva_source = RPMQV_PACKAGE;
432     qva->qva_fflags = RPMFILE_ALL;
433     qva->qva_mode = ' ';
434     qva->qva_char = ' ';
435 #endif
436
437 #ifdef  IAM_RPMBT
438     ba->buildRootOverride = _free(ba->buildRootOverride);
439     ba->targets = _free(ba->targets);
440     memset(ba, 0, sizeof(*ba));
441     ba->buildMode = ' ';
442     ba->buildChar = ' ';
443 #endif
444
445 #ifdef  IAM_RPMDB
446     memset(da, 0, sizeof(*da));
447 #endif
448
449 #ifdef  IAM_RPMK
450     ka->qva_queryFormat = _free(ka->qva_queryFormat);
451     memset(ka, 0, sizeof(*ka));
452     ka->qva_source = RPMQV_PACKAGE;
453     ka->qva_fflags = RPMFILE_ALL;
454     ka->qva_mode = ' ';
455     ka->qva_char = ' ';
456 #endif
457
458 #ifdef  IAM_RPMEIU
459     ia->relocations = _free(ia->relocations);
460     memset(ia, 0, sizeof(*ia));
461     ia->transFlags = RPMTRANS_FLAG_NONE;
462     ia->probFilter = RPMPROB_FILTER_NONE;
463     ia->installInterfaceFlags = INSTALL_NONE;
464     ia->eraseInterfaceFlags = UNINSTALL_NONE;
465 #endif
466
467     while ((arg = poptGetNextOpt(optCon)) > 0) {
468         optArg = poptGetOptArg(optCon);
469
470         switch (arg) {
471             
472         case 'v':
473             rpmIncreaseVerbosity();
474             /*@switchbreak@*/ break;
475
476 /* XXX options used in multiple rpm modes */
477 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
478         case POPT_NOMD5:
479 #ifdef  IAM_RPMQV
480             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
481                 qva->qva_flags |= VERIFY_MD5;
482             else
483 #endif
484 #ifdef  IAM_RPMK
485             if (bigMode & MODES_K)
486                 ka->qva_flags |= VERIFY_MD5;
487             else
488 #endif
489 #ifdef IAM_RPMEIU
490             if (bigMode & MODES_IE)
491                 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
492             else
493 #endif
494                 {};
495             /*@switchbreak@*/ break;
496 #endif  /* IAM_RPMQV || IAM_RPMK */
497
498 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
499         case POPT_NODEPS:
500 #ifdef  IAM_RPMQV
501             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
502                 qva->qva_flags |= VERIFY_DEPS;
503             else
504 #endif
505 #ifdef  IAM_RPMEIU
506             if ((bigMode & MODES_IE) ||
507                 (ia->installInterfaceFlags &
508             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
509                 ia->noDeps = 1;
510             else
511 #endif
512 #ifdef  IAM_RPMBT
513             if ((bigMode & MODES_BT) || ba->buildMode != ' ')
514                 ba->noDeps = 1;
515             else
516 #endif
517                 /*@-ifempty@*/ ;
518             /*@switchbreak@*/ break;
519
520         case POPT_FORCE:
521 #ifdef  IAM_RPMEIU
522             if ((bigMode & MODES_IE) ||
523                 (ia->installInterfaceFlags &
524             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
525                 ia->probFilter |=
526                         ( RPMPROB_FILTER_REPLACEPKG
527                         | RPMPROB_FILTER_REPLACEOLDFILES
528                         | RPMPROB_FILTER_REPLACENEWFILES
529                         | RPMPROB_FILTER_OLDPACKAGE);
530             else
531 #endif
532 #ifdef  IAM_RPMBT
533             if ((bigMode & MODES_BT) || ba->buildMode != ' ')
534                 ba->force = 1;
535             else
536 #endif
537                 /*@-ifempty@*/ ;
538             /*@switchbreak@*/ break;
539
540         case 'i':
541 #ifdef  IAM_RPMQV
542             if (bigMode == MODE_QUERY || qva->qva_mode == 'q') {
543                 /*@-nullassign -readonlytrans@*/
544                 const char * infoCommand[] = { "--info", NULL };
545                 /*@=nullassign =readonlytrans@*/
546                 (void) poptStuffArgs(optCon, infoCommand);
547             } else
548 #endif
549 #ifdef  IAM_RPMEIU
550             if (bigMode == MODE_INSTALL ||
551                 (ia->installInterfaceFlags &
552                     (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)))
553                 /*@-ifempty@*/ ;
554             else if (bigMode == MODE_UNKNOWN) {
555                 /*@-nullassign -readonlytrans@*/
556                 const char * installCommand[] = { "--install", NULL };
557                 /*@=nullassign =readonlytrans@*/
558                 (void) poptStuffArgs(optCon, installCommand);
559             } else
560 #endif
561                 /*@-ifempty@*/ ;
562             /*@switchbreak@*/ break;
563
564         case POPT_NOSCRIPTS:
565 #ifdef  IAM_RPMQV
566             if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
567                 qva->qva_flags |= VERIFY_SCRIPT;
568             else
569 #endif
570 #ifdef  IAM_RPMEIU
571             if ((bigMode & MODES_IE) ||
572                 (ia->installInterfaceFlags &
573             (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
574                 ia->transFlags |= (_noTransScripts | _noTransTriggers);
575             else
576 #endif
577                 /*@-ifempty@*/ ;
578             /*@switchbreak@*/ break;
579
580 #endif  /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
581
582         case GETOPT_DEFINEMACRO:
583             if (optArg) {
584                 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
585 /*@i@*/         (void) rpmDefineMacro(rpmCLIMacroContext, optArg,RMIL_CMDLINE);
586             }
587             noUsageMsg = 1;
588             /*@switchbreak@*/ break;
589
590         case GETOPT_EVALMACRO:
591             if (optArg) {
592                 const char *val = rpmExpand(optArg, NULL);
593                 fprintf(stdout, "%s\n", val);
594                 val = _free(val);
595             }
596             noUsageMsg = 1;
597             /*@switchbreak@*/ break;
598
599 #if defined(GETOPT_RCFILE)
600         case GETOPT_RCFILE:
601             fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
602             fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
603             exit(EXIT_FAILURE);
604             /*@notreached@*/ break;
605 #endif
606
607         default:
608             fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
609             exit(EXIT_FAILURE);
610         }
611     }
612
613     if (quiet)
614         rpmSetVerbosity(RPMMESS_QUIET);
615
616     if (showVersion) printVersion();
617
618     if (arg < -1) {
619         fprintf(stderr, "%s: %s\n", 
620                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
621                 poptStrerror(arg));
622         exit(EXIT_FAILURE);
623     }
624
625 #ifdef  IAM_RPMBT
626     switch (ba->buildMode) {
627     case 'b':   bigMode = MODE_BUILD;           break;
628     case 't':   bigMode = MODE_TARBUILD;        break;
629     case 'B':   bigMode = MODE_REBUILD;         break;
630     case 'C':   bigMode = MODE_RECOMPILE;       break;
631     }
632
633     if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
634         bigMode = MODE_BUILD;
635
636     if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
637         bigMode = MODE_BUILD;
638
639     if (ba->buildRootOverride && bigMode != MODE_BUILD &&
640         bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
641         argerror("--buildroot may only be used during package builds");
642     }
643 #endif  /* IAM_RPMBT */
644     
645 #ifdef  IAM_RPMDB
646   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
647     if (da->init) {
648         if (bigMode != MODE_UNKNOWN) 
649             argerror(_("only one major mode may be specified"));
650         else
651             bigMode = MODE_INITDB;
652     } else
653     if (da->rebuild) {
654         if (bigMode != MODE_UNKNOWN) 
655             argerror(_("only one major mode may be specified"));
656         else
657             bigMode = MODE_REBUILDDB;
658     } else
659     if (da->verify) {
660         if (bigMode != MODE_UNKNOWN) 
661             argerror(_("only one major mode may be specified"));
662         else
663             bigMode = MODE_VERIFYDB;
664     }
665   }
666 #endif  /* IAM_RPMDB */
667
668 #ifdef  IAM_RPMQV
669   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
670     switch (qva->qva_mode) {
671     case 'q':   bigMode = MODE_QUERY;           break;
672     case 'V':   bigMode = MODE_VERIFY;          break;
673     case 'Q':   bigMode = MODE_QUERYTAGS;       break;
674     }
675
676     if (qva->qva_sourceCount) {
677         if (qva->qva_sourceCount > 2)
678             argerror(_("one type of query/verify may be performed at a "
679                         "time"));
680     }
681     if (qva->qva_flags && (bigMode & ~MODES_QV)) 
682         argerror(_("unexpected query flags"));
683
684     if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) 
685         argerror(_("unexpected query format"));
686
687     if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) 
688         argerror(_("unexpected query source"));
689   }
690 #endif  /* IAM_RPMQV */
691
692 #ifdef  IAM_RPMEIU
693   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
694     {   int iflags = (ia->installInterfaceFlags &
695                 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
696         int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
697
698         if (iflags & eflags)
699             argerror(_("only one major mode may be specified"));
700         else if (iflags)
701             bigMode = MODE_INSTALL;
702         else if (eflags)
703             bigMode = MODE_ERASE;
704     }
705 #endif  /* IAM_RPMQV */
706
707 #ifdef  IAM_RPMK
708   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
709         switch (ka->qva_mode) {
710         case RPMSIGN_NONE:
711             ka->sign = 0;
712             break;
713         case RPMSIGN_IMPORT_PUBKEY:
714         case RPMSIGN_CHK_SIGNATURE:
715             bigMode = MODE_CHECKSIG;
716             ka->sign = 0;
717             break;
718         case RPMSIGN_ADD_SIGNATURE:
719         case RPMSIGN_NEW_SIGNATURE:
720             bigMode = MODE_RESIGN;
721             ka->sign = 1;
722             break;
723         }
724   }
725 #endif  /* IAM_RPMK */
726
727     /* XXX TODO: never happens. */
728     if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
729         argerror(_("--dbpath given for operation that does not use a "
730                         "database"));
731
732 #if defined(IAM_RPMEIU)
733     if (!( bigMode == MODE_INSTALL ) &&
734 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
735         argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
736     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
737         argerror(_("files may only be relocated during package installation"));
738
739     if (ia->relocations && ia->prefix)
740         argerror(_("only one of --prefix or --relocate may be used"));
741
742     if (bigMode != MODE_INSTALL && ia->relocations)
743         argerror(_("--relocate and --excludepath may only be used when installing new packages"));
744
745     if (bigMode != MODE_INSTALL && ia->prefix)
746         argerror(_("--prefix may only be used when installing new packages"));
747
748     if (ia->prefix && ia->prefix[0] != '/') 
749         argerror(_("arguments to --prefix must begin with a /"));
750
751     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
752         argerror(_("--hash (-h) may only be specified during package "
753                         "installation"));
754
755     if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
756         argerror(_("--percent may only be specified during package "
757                         "installation"));
758
759     if (bigMode != MODE_INSTALL &&
760  (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
761         argerror(_("--replacefiles may only be specified during package "
762                         "installation"));
763
764     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
765         argerror(_("--replacepkgs may only be specified during package "
766                         "installation"));
767
768     if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
769         argerror(_("--excludedocs may only be specified during package "
770                    "installation"));
771
772     if (bigMode != MODE_INSTALL && ia->incldocs)
773         argerror(_("--includedocs may only be specified during package "
774                    "installation"));
775
776     if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
777         argerror(_("only one of --excludedocs and --includedocs may be "
778                  "specified"));
779   
780     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
781         argerror(_("--ignorearch may only be specified during package "
782                    "installation"));
783
784     if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
785         argerror(_("--ignoreos may only be specified during package "
786                    "installation"));
787
788     if (bigMode != MODE_INSTALL &&
789         (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
790         argerror(_("--ignoresize may only be specified during package "
791                    "installation"));
792
793     if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
794         argerror(_("--allmatches may only be specified during package "
795                    "erasure"));
796
797     if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
798         argerror(_("--allfiles may only be specified during package "
799                    "installation"));
800
801     if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
802         bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
803         argerror(_("--justdb may only be specified during package "
804                    "installation and erasure"));
805
806     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
807         (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
808         argerror(_("script disabling options may only be specified during "
809                    "package installation and erasure"));
810
811     if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
812         (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
813         argerror(_("trigger disabling options may only be specified during "
814                    "package installation and erasure"));
815
816     if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
817         argerror(_("--nodeps may only be specified during package "
818                    "building, rebuilding, recompilation, installation,"
819                    "erasure, and verification"));
820
821     if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
822         argerror(_("--test may only be specified during package installation, "
823                  "erasure, and building"));
824 #endif  /* IAM_RPMEIU */
825
826     if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
827         argerror(_("--root (-r) may only be specified during "
828                  "installation, erasure, querying, and "
829                  "database rebuilds"));
830
831     if (rootdir) {
832         switch (urlIsURL(rootdir)) {
833         default:
834             if (bigMode & MODES_FOR_ROOT)
835                 break;
836             /*@fallthrough@*/
837         case URL_IS_UNKNOWN:
838             if (rootdir[0] != '/')
839                 argerror(_("arguments to --root (-r) must begin with a /"));
840             break;
841         }
842     }
843
844 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
845     if (0
846 #if defined(IAM_RPMBT)
847     || ba->sign 
848 #endif
849 #if defined(IAM_RPMK)
850     || ka->sign
851 #endif
852     )
853     /*@-branchstate@*/
854     {
855         if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
856             bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD)
857         {
858             const char ** av;
859             struct stat sb;
860             int errors = 0;
861
862             if ((av = poptGetArgs(optCon)) == NULL) {
863                 fprintf(stderr, _("no files to sign\n"));
864                 errors++;
865             } else
866             while (*av) {
867                 if (stat(*av, &sb)) {
868                     fprintf(stderr, _("cannot access file %s\n"), *av);
869                     errors++;
870                 }
871                 av++;
872             }
873
874             if (errors) {
875                 ec = errors;
876                 goto exit;
877             }
878
879             if (poptPeekArg(optCon)) {
880                 int sigTag;
881                 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
882                   case 0:
883                     break;
884                   case RPMSIGTAG_PGP:
885                     if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
886                         !rpmDetectPGPVersion(NULL)) {
887                         fprintf(stderr, _("pgp not found: "));
888                         ec = EXIT_FAILURE;
889                         goto exit;
890                     }   /*@fallthrough@*/
891                   case RPMSIGTAG_GPG:
892                     passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
893                     if (passPhrase == NULL) {
894                         fprintf(stderr, _("Pass phrase check failed\n"));
895                         ec = EXIT_FAILURE;
896                         goto exit;
897                     }
898                     fprintf(stderr, _("Pass phrase is good.\n"));
899                     passPhrase = xstrdup(passPhrase);
900                     break;
901                   default:
902                     fprintf(stderr,
903                             _("Invalid %%_signature spec in macro file.\n"));
904                     ec = EXIT_FAILURE;
905                     goto exit;
906                     /*@notreached@*/ break;
907                 }
908             }
909         } else {
910             argerror(_("--sign may only be used during package building"));
911         }
912     } else {
913         /* Make rpmLookupSignatureType() return 0 ("none") from now on */
914         (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
915     }
916     /*@=branchstate@*/
917 #endif  /* IAM_RPMBT || IAM_RPMK */
918
919     if (pipeOutput) {
920         (void) pipe(p);
921
922         if (!(pipeChild = fork())) {
923             (void) close(p[1]);
924             (void) dup2(p[0], STDIN_FILENO);
925             (void) close(p[0]);
926             (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
927             fprintf(stderr, _("exec failed\n"));
928         }
929
930         (void) close(p[0]);
931         (void) dup2(p[1], STDOUT_FILENO);
932         (void) close(p[1]);
933     }
934         
935     ts = rpmtransCreateSet(NULL, rootdir);
936     switch (bigMode) {
937 #ifdef  IAM_RPMDB
938     case MODE_INITDB:
939         (void) rpmdbInit(rootdir, 0644);
940         break;
941
942     case MODE_REBUILDDB:
943         ec = rpmdbRebuild(rootdir);
944         break;
945     case MODE_VERIFYDB:
946         ec = rpmdbVerify(rootdir);
947         break;
948 #endif  /* IAM_RPMDB */
949
950 #ifdef  IAM_RPMBT
951     case MODE_REBUILD:
952     case MODE_RECOMPILE:
953     {   const char * pkg;
954
955         while (!rpmIsVerbose())
956             rpmIncreaseVerbosity();
957
958         if (!poptPeekArg(optCon))
959             argerror(_("no packages files given for rebuild"));
960
961         ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
962         if (bigMode == MODE_REBUILD) {
963             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
964             ba->buildAmount |= RPMBUILD_RMSOURCE;
965             ba->buildAmount |= RPMBUILD_RMSPEC;
966             ba->buildAmount |= RPMBUILD_CLEAN;
967             ba->buildAmount |= RPMBUILD_RMBUILD;
968         }
969
970         while ((pkg = poptGetArg(optCon))) {
971             const char * specFile = NULL;
972
973             ba->cookie = NULL;
974             ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
975             if (ec == 0) {
976                 ba->rootdir = rootdir;
977                 ba->passPhrase = passPhrase;
978                 ec = build(ts, specFile, ba, rcfile);
979             }
980             ba->cookie = _free(ba->cookie);
981             specFile = _free(specFile);
982
983             if (ec)
984                 /*@loopbreak@*/ break;
985         }
986
987     }   break;
988
989     case MODE_BUILD:
990     case MODE_TARBUILD:
991     {   const char * pkg;
992         while (!rpmIsVerbose())
993             rpmIncreaseVerbosity();
994        
995         switch (ba->buildChar) {
996         case 'a':
997             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
998             /*@fallthrough@*/
999         case 'b':
1000             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
1001             ba->buildAmount |= RPMBUILD_CLEAN;
1002             /*@fallthrough@*/
1003         case 'i':
1004             ba->buildAmount |= RPMBUILD_INSTALL;
1005             if ((ba->buildChar == 'i') && ba->shortCircuit)
1006                 /*@innerbreak@*/ break;
1007             /*@fallthrough@*/
1008         case 'c':
1009             ba->buildAmount |= RPMBUILD_BUILD;
1010             if ((ba->buildChar == 'c') && ba->shortCircuit)
1011                 /*@innerbreak@*/ break;
1012             /*@fallthrough@*/
1013         case 'p':
1014             ba->buildAmount |= RPMBUILD_PREP;
1015             /*@innerbreak@*/ break;
1016             
1017         case 'l':
1018             ba->buildAmount |= RPMBUILD_FILECHECK;
1019             /*@innerbreak@*/ break;
1020         case 's':
1021             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
1022             /*@innerbreak@*/ break;
1023         }
1024
1025         if (!poptPeekArg(optCon)) {
1026             if (bigMode == MODE_BUILD)
1027                 argerror(_("no spec files given for build"));
1028             else
1029                 argerror(_("no tar files given for build"));
1030         }
1031
1032         while ((pkg = poptGetArg(optCon))) {
1033             ba->rootdir = rootdir;
1034             ba->passPhrase = passPhrase;
1035             ba->cookie = NULL;
1036             ec = build(ts, pkg, ba, rcfile);
1037             if (ec)
1038                 /*@loopbreak@*/ break;
1039             rpmFreeMacros(NULL);
1040             (void) rpmReadConfigFiles(rcfile, NULL);
1041         }
1042     }   break;
1043 #endif  /* IAM_RPMBT */
1044
1045 #ifdef  IAM_RPMEIU
1046     case MODE_ERASE:
1047         if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
1048
1049         if (!poptPeekArg(optCon)) {
1050             if (ia->rbtid == 0)
1051                 argerror(_("no packages given for erase"));
1052 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
1053 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
1054             ec += rpmRollback(ts, ia, NULL);
1055         } else {
1056             ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon));
1057         }
1058         break;
1059
1060     case MODE_INSTALL:
1061
1062         /* RPMTRANS_FLAG_BUILD_PROBS */
1063         /* RPMTRANS_FLAG_KEEPOBSOLETE */
1064
1065         if (!ia->incldocs) {
1066             if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
1067                 ;
1068             else if (rpmExpandNumeric("%{_excludedocs}"))
1069                 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
1070         }
1071
1072         if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
1073
1074         /* we've already ensured !(!ia->prefix && !ia->relocations) */
1075         /*@-branchstate@*/
1076         if (ia->prefix) {
1077             ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
1078             ia->relocations[0].oldPath = NULL;   /* special case magic */
1079             ia->relocations[0].newPath = ia->prefix;
1080             ia->relocations[1].oldPath = NULL;
1081             ia->relocations[1].newPath = NULL;
1082         } else if (ia->relocations) {
1083             ia->relocations = xrealloc(ia->relocations, 
1084                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
1085             ia->relocations[ia->numRelocations].oldPath = NULL;
1086             ia->relocations[ia->numRelocations].newPath = NULL;
1087         }
1088         /*@=branchstate@*/
1089
1090         if (!poptPeekArg(optCon)) {
1091             if (ia->rbtid == 0)
1092                 argerror(_("no packages given for install"));
1093 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
1094 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
1095 /*@i@*/     ec += rpmRollback(ts, ia, NULL);
1096         } else {
1097             /*@-compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */
1098             ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
1099             /*@=compmempass@*/
1100         }
1101         break;
1102
1103 #endif  /* IAM_RPMEIU */
1104
1105 #ifdef  IAM_RPMQV
1106     case MODE_QUERY:
1107         if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
1108             argerror(_("no arguments given for query"));
1109         ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
1110         /* XXX don't overflow single byte exit status */
1111         if (ec > 255) ec = 255;
1112         break;
1113
1114     case MODE_VERIFY:
1115     {   rpmVerifyFlags verifyFlags = VERIFY_ALL;
1116
1117         verifyFlags &= ~qva->qva_flags;
1118         qva->qva_flags = (rpmQueryFlags) verifyFlags;
1119
1120         if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
1121             argerror(_("no arguments given for verify"));
1122         ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon));
1123         /* XXX don't overflow single byte exit status */
1124         if (ec > 255) ec = 255;
1125     }   break;
1126
1127     case MODE_QUERYTAGS:
1128         if (argc != 2)
1129             argerror(_("unexpected arguments to --querytags "));
1130
1131         rpmDisplayQueryTags(stdout);
1132         break;
1133 #endif  /* IAM_RPMQV */
1134
1135 #ifdef IAM_RPMK
1136     case MODE_CHECKSIG:
1137     {   rpmVerifyFlags verifyFlags =
1138                 (VERIFY_MD5|VERIFY_DIGEST|VERIFY_SIGNATURE);
1139
1140         verifyFlags &= ~ka->qva_flags;
1141         ka->qva_flags = (rpmQueryFlags) verifyFlags;
1142     }   /*@fallthrough@*/
1143     case MODE_RESIGN:
1144         if (!poptPeekArg(optCon))
1145             argerror(_("no arguments given"));
1146         ka->passPhrase = passPhrase;
1147         ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon));
1148         /* XXX don't overflow single byte exit status */
1149         if (ec > 255) ec = 255;
1150         break;
1151 #endif  /* IAM_RPMK */
1152         
1153 #if !defined(IAM_RPMQV)
1154     case MODE_QUERY:
1155     case MODE_VERIFY:
1156     case MODE_QUERYTAGS:
1157 #endif
1158 #if !defined(IAM_RPMK)
1159     case MODE_CHECKSIG:
1160     case MODE_RESIGN:
1161 #endif
1162 #if !defined(IAM_RPMDB)
1163     case MODE_INITDB:
1164     case MODE_REBUILDDB:
1165     case MODE_VERIFYDB:
1166 #endif
1167 #if !defined(IAM_RPMBT)
1168     case MODE_BUILD:
1169     case MODE_REBUILD:
1170     case MODE_RECOMPILE:
1171     case MODE_TARBUILD:
1172 #endif
1173 #if !defined(IAM_RPMEIU)
1174     case MODE_INSTALL:
1175     case MODE_ERASE:
1176 #endif
1177     case MODE_UNKNOWN:
1178         if (!showVersion && !help && !noUsageMsg) printUsage();
1179         break;
1180     }
1181
1182 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
1183 exit:
1184 #endif  /* IAM_RPMBT || IAM_RPMK */
1185
1186     ts = rpmtransFree(ts);
1187
1188     optCon = poptFreeContext(optCon);
1189     rpmFreeMacros(NULL);
1190 /*@i@*/ rpmFreeMacros(rpmCLIMacroContext);
1191     rpmFreeRpmrc();
1192
1193     if (pipeChild) {
1194         (void) fclose(stdout);
1195         (void) waitpid(pipeChild, &status, 0);
1196     }
1197
1198     /* keeps memory leak checkers quiet */
1199     freeNames();
1200     freeFilesystems();
1201 /*@i@*/ urlFreeCache();
1202     rpmlogClose();
1203     dbiTags = _free(dbiTags);
1204
1205 #ifdef  IAM_RPMQV
1206     qva->qva_queryFormat = _free(qva->qva_queryFormat);
1207 #endif
1208
1209 #ifdef  IAM_RPMBT
1210     ba->buildRootOverride = _free(ba->buildRootOverride);
1211     ba->targets = _free(ba->targets);
1212 #endif
1213
1214 #ifdef  IAM_RPMEIU
1215     ia->relocations = _free(ia->relocations);
1216 #endif
1217
1218 #if HAVE_MCHECK_H && HAVE_MTRACE
1219     /*@-noeffect@*/
1220     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
1221     /*@=noeffect@*/
1222 #endif
1223     /*@-globstate@*/
1224     return ec;
1225     /*@=globstate@*/
1226 }
1227 /*@=mods@*/