- Main Page
- Related Pages
- Modules
- Data Structures
- Files

# lib/poptALL.c

Go to the documentation of this file.

    00001
    00006 #include "system.h"
    00007 const char *__progname;
    00008
    00009 #include <rpmio.h>
    00010 #include <rpmcli.h>
    00011 #include <fs.h>                 /* XXX rpmFreeFilesystems() */
    00012 #include <rpmns.h>              /* XXX rpmnsClean() */
    00013 #include <fts.h>
    00014 #include <mire.h>
    00015
    00016 #define _RPMPGP_INTERNAL
    00017 #if defined(WITH_BEECRYPT)
    00018 #define _RPMBC_INTERNAL
    00019 #include <rpmbc.h>
    00020 #endif
    00021 #if defined(WITH_GCRYPT)
    00022 #define _RPMGC_INTERNAL
    00023 #include <rpmgc.h>
    00024 #endif
    00025 #if defined(WITH_NSS)
    00026 #define _RPMNSS_INTERNAL
    00027 #include <rpmnss.h>
    00028 #endif
    00029 #if defined(WITH_SSL)
    00030 #define _RPMSSL_INTERNAL
    00031 #include <rpmssl.h>
    00032 #endif
    00033
    00034 #include "debug.h"
    00035
    00036 #define POPT_SHOWVERSION        -999
    00037 #define POPT_SHOWRC             -998
    00038 #define POPT_QUERYTAGS          -997
    00039 #define POPT_PREDEFINE          -996
    00040 #ifdef  DEAD    /* XXX remember the previous definition however. */
    00041 #define POPT_RCFILE             -995
    00042 #endif
    00043 #define POPT_UNDEFINE           -994
    00044 #define POPT_CRYPTO             -993
    00045
    00046 /*@access headerTagIndices @*/          /* XXX rpmcliFini */
    00047 /*@access headerTagTableEntry @*/       /* XXX rpmcliFini */
    00048
    00049 /*@unchecked@*/
    00050 static int _debug = 0;
    00051
    00052 /*@-exportheadervar@*/
    00053 /*@unchecked@*/
    00054 extern int _rpmds_nopromote;
    00055
    00056 /*@unchecked@*/
    00057 extern int _cpio_debug;
    00058
    00059 /*@unchecked@*/
    00060 extern int _fps_debug;
    00061
    00062 /*@unchecked@*/
    00063 extern int _fsm_debug;
    00064
    00065 /*@unchecked@*/
    00066 extern int _fsm_threads;
    00067
    00068 /*@unchecked@*/
    00069 extern int _hdr_debug;
    00070
    00071 /*@unchecked@*/
    00072 extern int _mire_debug;
    00073
    00074 /*@unchecked@*/
    00075 extern int _print_pkts;
    00076
    00077 /*@unchecked@*/
    00078 extern int _psm_debug;
    00079
    00080 /*@unchecked@*/
    00081 extern int _psm_threads;
    00082
    00083 /*@unchecked@*/
    00084 extern int _rpmal_debug;
    00085
    00086 /*@unchecked@*/
    00087 extern int _rpmdb_debug;
    00088
    00089 /*@unchecked@*/
    00090 extern int _rpmds_debug;
    00091
    00092 /* XXX avoid -lrpmbuild linkage. */
    00093 /*@unchecked@*/
    00094        int _rpmfc_debug;
    00095
    00096 /*@unchecked@*/
    00097 extern int _rpmfi_debug;
    00098
    00099 /*@unchecked@*/
    00100 extern int _rpmgi_debug;
    00101
    00102 /*@unchecked@*/
    00103 extern int _rpmmg_debug;
    00104
    00105 /*@unchecked@*/
    00106 extern int _rpmps_debug;
    00107
    00108 /*@unchecked@*/
    00109 extern int _rpmsq_debug;
    00110
    00111 /*@unchecked@*/
    00112 extern int _rpmsx_debug;
    00113
    00114 /*@unchecked@*/
    00115 extern int _rpmte_debug;
    00116
    00117 /*@unchecked@*/
    00118 extern int _rpmts_debug;
    00119
    00120 /*@unchecked@*/
    00121 extern int _rpmwf_debug;
    00122
    00123 /*@unchecked@*/
    00124 extern int _xar_debug;
    00125
    00126 /*@unchecked@*/
    00127 extern int _rpmts_macros;
    00128
    00129 /*@unchecked@*/
    00130 extern int _rpmts_stats;
    00131
    00132 /*@unchecked@*/
    00133 extern int _hdr_stats;
    00134
    00135 /*@unchecked@*/
    00136 extern int _tar_debug;
    00137
    00138 /*@unchecked@*/
    00139 extern int noLibio;
    00140 /*@=exportheadervar@*/
    00141
    00142 /*@unchecked@*/ /*@null@*/
    00143 const char * rpmcliPipeOutput = NULL;
    00144
    00145 /*@unchecked@*/
    00146 const char * rpmcliRootDir = "/";
    00147
    00148 /*@unchecked@*/
    00149 rpmQueryFlags rpmcliQueryFlags;
    00150
    00151 /*@unchecked@*/ /*@null@*/
    00152 const char * rpmcliTargets = NULL;
    00153
    00154 /*@-exportheadervar@*/
    00155 /*@unchecked@*/
    00156 extern int _ftp_debug;
    00157 /*@unchecked@*/
    00158 extern int _av_debug;
    00159 /*@unchecked@*/
    00160 extern int _dav_debug;
    00161
    00162 /*@unchecked@*/
    00163 extern int noLibio;
    00164
    00165 /*@unchecked@*/
    00166 extern int _rpmio_debug;
    00167 /*@=exportheadervar@*/
    00168
    00169 /*@unchecked@*/
    00170 static int rpmcliInitialized = -1;
    00171
    00175 static void printVersion(FILE * fp)
    00176         /*@globals rpmEVR, fileSystem @*/
    00177         /*@modifies *fp, fileSystem @*/
    00178 {
    00179     fprintf(fp, _("%s (" RPM_NAME ") %s\n"), __progname, rpmEVR);
    00180     if (rpmIsVerbose())
    00181         fprintf(fp, "rpmlib 0x%08x,0x%08x,0x%08x\n",
    00182             rpmlibVersion(), rpmlibTimestamp(), rpmlibVendor());
    00183 }
    00184
    00185 void rpmcliConfigured(void)
    00186         /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
    00187                 h_errno, fileSystem, internalState @*/
    00188         /*@modifies rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
    00189                 fileSystem, internalState @*/
    00190 {
    00191
    00192     if (rpmcliInitialized < 0) {
    00193         char * t = NULL;
    00194         if (rpmcliTargets != NULL) {
    00195             char *te;
    00196             t = xstrdup(rpmcliTargets);
    00197             if ((te = strchr(t, ',')) != NULL)
    00198                 *te = '\0';
    00199         }
    00200         rpmcliInitialized = rpmReadConfigFiles(NULL, t);
    00201         t = _free(t);
    00202     }
    00203     if (rpmcliInitialized)
    00204         exit(EXIT_FAILURE);
    00205 }
    00206
    00209 static void rpmcliAllArgCallback(poptContext con,
    00210                 /*@unused@*/ enum poptCallbackReason reason,
    00211                 const struct poptOption * opt, const char * arg,
    00212                 /*@unused@*/ const void * data)
    00213         /*@globals rpmcliTargets, rpmcliQueryFlags, rpmCLIMacroContext,
    00214                 rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
    00215         /*@modifies con, rpmcliTargets, rpmcliQueryFlags, rpmCLIMacroContext,
    00216                 rpmGlobalMacroContext, fileSystem, internalState @*/
    00217 {
    00218
    00219     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
    00220     if (opt->arg == NULL)
    00221     switch (opt->val) {
    00222     case 'q':
    00223         rpmSetVerbosity(RPMLOG_WARNING);
    00224         break;
    00225     case 'v':
    00226         rpmIncreaseVerbosity();
    00227         break;
    00228     case POPT_PREDEFINE:
    00229         (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
    00230         break;
    00231     case 'D':
    00232     {   char *s, *t;
    00233         /* XXX Convert '-' in macro name to underscore, skip leading %. */
    00234         s = t = xstrdup(arg);
    00235         while (*t && !xisspace(*t)) {
    00236             if (*t == '-') *t = '_';
    00237             t++;
    00238         }
    00239         t = s;
    00240         if (*t == '%') t++;
    00241         rpmcliConfigured();
    00242 /*@-type@*/
    00243         /* XXX adding macro to global context isn't Right Thing Todo. */
    00244         (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
    00245         (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
    00246 /*@=type@*/
    00247         s = _free(s);
    00248     }   break;
    00249     case POPT_UNDEFINE:
    00250     {   char *s, *t;
    00251         /* XXX Convert '-' in macro name to underscore, skip leading %. */
    00252         s = t = xstrdup(arg);
    00253         while (*t && !xisspace(*t)) {
    00254             if (*t == '-') *t = '_';
    00255             t++;
    00256         }
    00257         t = s;
    00258         if (*t == '%') t++;
    00259 /*@-type@*/
    00260         rpmcliConfigured();
    00261         (void) rpmUndefineMacro(NULL, t);
    00262         (void) rpmUndefineMacro(rpmCLIMacroContext, t);
    00263 /*@=type@*/
    00264         s = _free(s);
    00265     }   break;
    00266     case POPT_CRYPTO:
    00267         rpmcliConfigured();
    00268         {   const char *val = rpmExpand(arg, NULL);
    00269 #if defined(WITH_BEECRYPT)
    00270             if (!xstrcasecmp(val, "beecrypt") || !xstrcasecmp(val, "bc"))
    00271                 pgpImplVecs = &rpmbcImplVecs;
    00272 #endif
    00273 #if defined(WITH_GCRYPT)
    00274             if (!xstrcasecmp(val, "gcrypt") || !xstrcasecmp(val, "gc"))
    00275                 pgpImplVecs = &rpmgcImplVecs;
    00276 #endif
    00277 #if defined(WITH_NSS)
    00278             if (!xstrcasecmp(val, "NSS"))
    00279                 pgpImplVecs = &rpmnssImplVecs;
    00280 #endif
    00281 #if defined(WITH_SSL)
    00282             if (!xstrcasecmp(val, "OpenSSL") || !xstrcasecmp(val, "ssl"))
    00283                 pgpImplVecs = &rpmsslImplVecs;
    00284 #endif
    00285             val = _free(val);
    00286         }
    00287         break;
    00288     case 'E':
    00289         rpmcliConfigured();
    00290         {   const char *val = rpmExpand(arg, NULL);
    00291 #if defined(RPM_VENDOR_OPENPKG) /* no-extra-terminating-newline-on-eval */
    00292             size_t val_len;
    00293             val_len = strlen(val);
    00294             if (val[val_len - 1] == '\n')
    00295                 fwrite(val, val_len, 1, stdout);
    00296             else
    00297 #endif
    00298             fprintf(stdout, "%s\n", val);
    00299             val = _free(val);
    00300         }
    00301         break;
    00302     case POPT_SHOWVERSION:
    00303         printVersion(stdout);
    00304 /*@i@*/ con = rpmcliFini(con);
    00305         exit(EXIT_SUCCESS);
    00306         /*@notreached@*/ break;
    00307     case POPT_SHOWRC:
    00308         rpmcliConfigured();
    00309         (void) rpmShowRC(stdout);
    00310 /*@i@*/ con = rpmcliFini(con);
    00311         exit(EXIT_SUCCESS);
    00312         /*@notreached@*/ break;
    00313     case POPT_QUERYTAGS:
    00314         rpmDisplayQueryTags(NULL, NULL, NULL);
    00315 /*@i@*/ con = rpmcliFini(con);
    00316         exit(EXIT_SUCCESS);
    00317         /*@notreached@*/ break;
    00318 #if defined(POPT_RCFILE)
    00319     case POPT_RCFILE:           /* XXX FIXME: noop for now */
    00320         break;
    00321 #endif
    00322     case RPMCLI_POPT_NODIGEST:
    00323         rpmcliQueryFlags |= VERIFY_DIGEST;
    00324         pgpDigVSFlags |= _RPMVSF_NODIGESTS;
    00325         break;
    00326
    00327     case RPMCLI_POPT_NOSIGNATURE:
    00328         rpmcliQueryFlags |= VERIFY_SIGNATURE;
    00329         pgpDigVSFlags |= _RPMVSF_NOSIGNATURES;
    00330         break;
    00331
    00332     case RPMCLI_POPT_NOHDRCHK:
    00333         rpmcliQueryFlags |= VERIFY_HDRCHK;
    00334         pgpDigVSFlags |= RPMVSF_NOHDRCHK;
    00335         break;
    00336
    00337     case RPMCLI_POPT_TARGETPLATFORM:
    00338         if (rpmcliTargets == NULL)
    00339             rpmcliTargets = xstrdup(arg);
    00340         else {
    00341 /*@-modobserver @*/
    00342             char * t = (char *) rpmcliTargets;
    00343             size_t nb = strlen(t) + (sizeof(",")-1) + strlen(arg) + 1;
    00344 /*@i@*/     t = xrealloc(t, nb);
    00345             (void) stpcpy( stpcpy(t, ","), arg);
    00346             rpmcliTargets = t;
    00347 /*@=modobserver @*/
    00348         }
    00349         break;
    00350     }
    00351 }
    00352
    00353 /*@unchecked@*/
    00354 int ftsOpts = 0;
    00355
    00356 /*@unchecked@*/
    00357 struct poptOption rpmcliFtsPoptTable[] = {
    00358  { "comfollow", '\0', POPT_BIT_SET,     &ftsOpts, FTS_COMFOLLOW,
    00359         N_("FTS_COMFOLLOW: follow command line symlinks"), NULL },
    00360  { "logical", '\0', POPT_BIT_SET,       &ftsOpts, FTS_LOGICAL,
    00361         N_("FTS_LOGICAL: logical walk"), NULL },
    00362  { "nochdir", '\0', POPT_BIT_SET,       &ftsOpts, FTS_NOCHDIR,
    00363         N_("FTS_NOCHDIR: don't change directories"), NULL },
    00364  { "nostat", '\0', POPT_BIT_SET,        &ftsOpts, FTS_NOSTAT,
    00365         N_("FTS_NOSTAT: don't get stat info"), NULL },
    00366  { "physical", '\0', POPT_BIT_SET,      &ftsOpts, FTS_PHYSICAL,
    00367         N_("FTS_PHYSICAL: physical walk"), NULL },
    00368  { "seedot", '\0', POPT_BIT_SET,        &ftsOpts, FTS_SEEDOT,
    00369         N_("FTS_SEEDOT: return dot and dot-dot"), NULL },
    00370  { "xdev", '\0', POPT_BIT_SET,          &ftsOpts, FTS_XDEV,
    00371         N_("FTS_XDEV: don't cross devices"), NULL },
    00372  { "whiteout", '\0', POPT_BIT_SET,      &ftsOpts, FTS_WHITEOUT,
    00373         N_("FTS_WHITEOUT: return whiteout information"), NULL },
    00374    POPT_TABLEEND
    00375 };
    00376
    00377 /*@unchecked@*/
    00378 int global_depFlags;
    00379
    00380 /*@unchecked@*/
    00381 struct poptOption rpmcliDepFlagsPoptTable[] = {
    00382  { "aid", '\0', POPT_BIT_SET, &global_depFlags, RPMDEPS_FLAG_ADDINDEPS,
    00383         N_("add suggested packages to transaction"), NULL },
    00384  { "anaconda", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00385         &global_depFlags, RPMDEPS_FLAG_ANACONDA|RPMDEPS_FLAG_DEPLOOPS,
    00386         N_("use anaconda \"presentation order\""), NULL},
    00387  { "deploops", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00388         &global_depFlags, RPMDEPS_FLAG_DEPLOOPS,
    00389         N_("print dependency loops as warning"), NULL},
    00390  { "nosuggest", '\0', POPT_BIT_SET,
    00391         &global_depFlags, RPMDEPS_FLAG_NOSUGGEST,
    00392         N_("do not suggest missing dependency resolution(s)"), NULL},
    00393  { "noconflicts", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00394         &global_depFlags, RPMDEPS_FLAG_NOCONFLICTS,
    00395         N_("do not check added package conflicts"), NULL},
    00396  { "nolinktos", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00397         &global_depFlags, RPMDEPS_FLAG_NOLINKTOS,
    00398         N_("ignore added package requires on symlink targets"), NULL},
    00399  { "noobsoletes", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00400         &global_depFlags, RPMDEPS_FLAG_NOOBSOLETES,
    00401         N_("ignore added package obsoletes"), NULL},
    00402  { "noparentdirs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00403         &global_depFlags, RPMDEPS_FLAG_NOPARENTDIRS,
    00404         N_("ignore added package requires on file parent directory"), NULL},
    00405  { "norequires", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00406         &global_depFlags, RPMDEPS_FLAG_NOREQUIRES,
    00407         N_("do not check added package requires"), NULL},
    00408  { "noupgrade", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00409         &global_depFlags, RPMDEPS_FLAG_NOUPGRADE,
    00410         N_("ignore added package upgrades"), NULL},
    00411    POPT_TABLEEND
    00412 };
    00413
    00414 /*@-bitwisesigned -compmempass @*/
    00415 /*@unchecked@*/
    00416 struct poptOption rpmcliAllPoptTable[] = {
    00417 /*@-type@*/ /* FIX: cast? */
    00418  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
    00419         rpmcliAllArgCallback, 0, NULL, NULL },
    00420 /*@=type@*/
    00421
    00422  { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
    00423         NULL, NULL },
    00424
    00425  { "predefine", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_PREDEFINE,
    00426         N_("predefine MACRO with value EXPR"),
    00427         N_("'MACRO EXPR'") },
    00428  { "define", 'D', POPT_ARG_STRING, NULL, 'D',
    00429         N_("define MACRO with value EXPR"),
    00430         N_("'MACRO EXPR'") },
    00431  { "undefine", '\0', POPT_ARG_STRING, NULL, POPT_UNDEFINE,
    00432         N_("undefine MACRO"),
    00433         N_("'MACRO'") },
    00434  { "eval", 'E', POPT_ARG_STRING, NULL, 'E',
    00435         N_("print macro expansion of EXPR"),
    00436         N_("'EXPR'") },
    00437  { "macros", '\0', POPT_ARG_STRING, &rpmMacrofiles, 0,
    00438         N_("read <FILE:...> instead of default file(s)"),
    00439         N_("<FILE:...>") },
    00440  { "target", '\0', POPT_ARG_STRING, NULL,  RPMCLI_POPT_TARGETPLATFORM,
    00441         N_("specify target platform"), N_("CPU-VENDOR-OS") },
    00442
    00443  { "nodigest", '\0', 0, NULL, RPMCLI_POPT_NODIGEST,
    00444         N_("don't verify package digest(s)"), NULL },
    00445  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOHDRCHK,
    00446         N_("don't verify database header(s) when retrieved"), NULL },
    00447 #if defined(HAVE_LIBIO_H) && defined(_G_IO_IO_FILE_VERSION)
    00448  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
    00449         N_("disable use of libio(3) API"), NULL},
    00450 #endif
    00451  { "nosignature", '\0', 0, NULL, RPMCLI_POPT_NOSIGNATURE,
    00452         N_("don't verify package signature(s)"), NULL },
    00453
    00454  { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
    00455         N_("send stdout to CMD"),
    00456         N_("CMD") },
    00457  { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
    00458         N_("use ROOT as top level directory"),
    00459         N_("ROOT") },
    00460
    00461  { "querytags", '\0', 0, NULL, POPT_QUERYTAGS,
    00462         N_("display known query tags"), NULL },
    00463  { "quiet", '\0', 0, NULL, 'q',
    00464         N_("provide less detailed output"), NULL},
    00465  { "showrc", '\0', 0, NULL, POPT_SHOWRC,
    00466         N_("display final rpmrc and macro configuration"), NULL },
    00467  { "verbose", 'v', 0, NULL, 'v',
    00468         N_("provide more detailed output"), NULL},
    00469  { "version", '\0', 0, NULL, POPT_SHOWVERSION,
    00470         N_("print the version of rpm being used"), NULL },
    00471
    00472 #if defined(HAVE_LIBIO_H) && defined(_G_IO_IO_FILE_VERSION)
    00473  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
    00474        N_("disable use of libio(3) API"), NULL},
    00475 #endif
    00476
    00477  { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
    00478         NULL, NULL},
    00479
    00480  { "usecrypto",'\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_CRYPTO,
    00481         N_("select cryptography implementation"),
    00482         N_("CRYPTO") },
    00483
    00484  { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1,
    00485         N_("debug argv collections"), NULL},
    00486  { "cpiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_cpio_debug, -1,
    00487         N_("debug cpio payloads"), NULL},
    00488  { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1,
    00489         N_("debug WebDAV data stream"), NULL},
    00490  { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
    00491         NULL, NULL},
    00492  { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
    00493         N_("debug payload file state machine"), NULL},
    00494  { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
    00495         N_("use threads for file state machine"), NULL},
    00496  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
    00497         N_("debug FTP/HTTP data stream"), NULL},
    00498  { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
    00499         NULL, NULL},
    00500  { "macrosused", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_macros, -1,
    00501         NULL, NULL},
    00502  { "miredebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_mire_debug, -1,
    00503         NULL, NULL},
    00504 #ifdef  DYING
    00505  { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
    00506         N_("debug option/argument processing"), NULL},
    00507 #endif
    00508  { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
    00509         NULL, NULL},
    00510  { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
    00511         N_("debug package state machine"), NULL},
    00512  { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
    00513         N_("use threads for package state machine"), NULL},
    00514  { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
    00515         NULL, NULL},
    00516  { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
    00517         NULL, NULL},
    00518  { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
    00519         NULL, NULL},
    00520  { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
    00521         NULL, NULL},
    00522  { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
    00523         NULL, NULL},
    00524  { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
    00525         NULL, NULL},
    00526  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
    00527         N_("debug rpmio I/O"), NULL},
    00528  { "rpmmgdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmg_debug, -1,
    00529         NULL, NULL},
    00530  { "rpmnsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmns_debug, -1,
    00531         NULL, NULL},
    00532  { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
    00533         NULL, NULL},
    00534  { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
    00535         NULL, NULL},
    00536  { "rpmsxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsx_debug, -1,
    00537         NULL, NULL},
    00538  { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
    00539         NULL, NULL},
    00540  { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
    00541         NULL, NULL},
    00542  { "rpmwfdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmwf_debug, -1,
    00543         NULL, NULL},
    00544  { "xardebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_xar_debug, -1,
    00545         NULL, NULL},
    00546  { "tardebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_tar_debug, -1,
    00547         N_("debug tar payloads"), NULL},
    00548  { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
    00549         NULL, NULL},
    00550  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
    00551         N_("debug URL cache handling"), NULL},
    00552
    00553    POPT_TABLEEND
    00554 };
    00555 /*@=bitwisesigned =compmempass @*/
    00556
    00557 poptContext
    00558 rpmcliFini(poptContext optCon)
    00559 {
    00560     /* XXX this should be done in the rpmioClean() wrapper. */
    00561     /* keeps memory leak checkers quiet */
    00562     rpmFreeMacros(NULL);
    00563 /*@i@*/ rpmFreeMacros(rpmCLIMacroContext);
    00564
    00565     rpmioClean();
    00566
    00567     rpmnsClean();
    00568
    00569     rpmFreeRpmrc();
    00570
    00571     rpmFreeFilesystems();
    00572 /*@i@*/ rpmcliTargets = _free(rpmcliTargets);
    00573
    00574     keyids = _free(keyids);
    00575
    00576     tagClean(NULL);     /* Free header tag indices. */
    00577
    00578     optCon = poptFreeContext(optCon);
    00579
    00580 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
    00581     /*@-noeffect@*/
    00582     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
    00583     /*@=noeffect@*/
    00584 #endif
    00585
    00586     return NULL;
    00587 }
    00588
    00589 static inline int checkfd(const char * devnull, int fdno, int flags)
    00590 {
    00591     struct stat sb;
    00592     int ret = 0;
    00593
    00594     if (fstat(fdno, &sb) == -1 && errno == EBADF)
    00595         ret = (open(devnull, flags) == fdno) ? 1 : 2;
    00596     return ret;
    00597 }
    00598
    00599 /*@-globstate@*/
    00600 poptContext
    00601 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
    00602 {
    00603     poptContext optCon;
    00604     char *path_buf, *path, *path_next;
    00605     int rc;
    00606
    00607 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
    00608     /*@-noeffect@*/
    00609     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
    00610     /*@=noeffect@*/
    00611 #endif
    00612 /*@-globs -mods@*/
    00613     setprogname(argv[0]);       /* Retrofit glibc __progname */
    00614
    00615     /* XXX glibc churn sanity */
    00616     if (__progname == NULL) {
    00617         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
    00618         else __progname = argv[0];
    00619     }
    00620 /*@=globs =mods@*/
    00621
    00622     /* Insure that stdin/stdout/stderr are open, lest stderr end up in rpmdb. */
    00623    {    static const char _devnull[] = "/dev/null";
    00624 #if defined(STDIN_FILENO)
    00625         (void) checkfd(_devnull, STDIN_FILENO, O_RDONLY);
    00626 #endif
    00627 #if defined(STDOUT_FILENO)
    00628         (void) checkfd(_devnull, STDOUT_FILENO, O_WRONLY);
    00629 #endif
    00630 #if defined(STDERR_FILENO)
    00631         (void) checkfd(_devnull, STDERR_FILENO, O_WRONLY);
    00632 #endif
    00633    }
    00634
    00635 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
    00636     (void) setlocale(LC_ALL, "" );
    00637     (void) bindtextdomain(PACKAGE, LOCALEDIR);
    00638     (void) textdomain(PACKAGE);
    00639 #endif
    00640
    00641     rpmSetVerbosity(RPMLOG_NOTICE);
    00642
    00643     if (optionsTable == NULL) {
    00644         /* Read rpm configuration (if not already read). */
    00645         rpmcliConfigured();
    00646         return NULL;
    00647     }
    00648
    00649 /*@-nullpass -temptrans@*/
    00650     optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
    00651 /*@=nullpass =temptrans@*/
    00652
    00653     /* read all RPM POPT configuration files */
    00654     path_buf = xstrdup(RPMPOPTFILES);
    00655     for (path = path_buf; path != NULL && *path != '\0'; path = path_next) {
    00656         const char **av;
    00657         int ac, i;
    00658
    00659         /* locate start of next path element */
    00660         path_next = strchr(path, ':');
    00661         if (path_next != NULL && *path_next == ':')
    00662             *path_next++ = '\0';
    00663         else
    00664             path_next = path + strlen(path);
    00665
    00666 #if defined(RPM_VENDOR_OPENPKG) /* security-sanity-check-rpmpopt-and-rpmmacros */
    00667         if (path[0] == '@' /* attention */) {
    00668             path++;
    00669             if (!rpmSecuritySaneFile(path)) {
    00670                 rpmlog(RPMLOG_WARNING, "existing POPT configuration file \"%s\" considered INSECURE -- not loaded\n", path);
    00671                 continue;
    00672             }
    00673         }
    00674 #endif
    00675
    00676         /* glob-expand the path element */
    00677         ac = 0;
    00678         av = NULL;
    00679         if ((i = rpmGlob(path, &ac, &av)) != 0)
    00680             continue;
    00681
    00682         /* work-off each resulting file from the path element */
    00683         for (i = 0; i < ac; i++) {
    00684             (void)poptReadConfigFile(optCon, av[i]);
    00685             av[i] = _free(av[i]);
    00686         }
    00687         av = _free(av);
    00688     }
    00689     path_buf = _free(path_buf);
    00690
    00691     /* read standard POPT configuration files */
    00692     (void) poptReadDefaultConfig(optCon, 1);
    00693
    00694     poptSetExecPath(optCon, USRLIBRPM, 1);
    00695
    00696     /* Process all options, whine if unknown. */
    00697     while ((rc = poptGetNextOpt(optCon)) > 0) {
    00698         const char * optArg = poptGetOptArg(optCon);
    00699         optArg = _free(optArg);
    00700         switch (rc) {
    00701         default:
    00702 /*@-nullpass@*/
    00703             fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
    00704                 __progname, rc);
    00705 /*@=nullpass@*/
    00706             exit(EXIT_FAILURE);
    00707
    00708             /*@notreached@*/ /*@switchbreak@*/ break;
    00709         }
    00710     }
    00711
    00712     if (rc < -1) {
    00713 /*@-nullpass@*/
    00714         fprintf(stderr, "%s: %s: %s\n", __progname,
    00715                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
    00716                 poptStrerror(rc));
    00717 /*@=nullpass@*/
    00718         exit(EXIT_FAILURE);
    00719     }
    00720
    00721     /* Read rpm configuration (if not already read). */
    00722     rpmcliConfigured();
    00723
    00724     if (_debug) {
    00725         rpmIncreaseVerbosity();
    00726         rpmIncreaseVerbosity();
    00727     }
    00728
    00729     /* Initialize header stat collection. */
    00730 /*@-mods@*/
    00731     _hdr_stats = _rpmts_stats;
    00732 /*@=mods@*/
    00733
    00734     return optCon;
    00735 }
    00736 /*@=globstate@*/