00001
00006 #include "system.h"
00007 const char *__progname;
00008
00009 #include <rpmio.h>
00010 #include <rpmcli.h>
00011 #include <fs.h>
00012 #include <rpmns.h>
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
00041 #define POPT_RCFILE -995
00042 #endif
00043 #define POPT_UNDEFINE -994
00044 #define POPT_CRYPTO -993
00045
00046
00047
00048
00049
00050 static int _debug = 0;
00051
00052
00053
00054 extern int _rpmds_nopromote;
00055
00056
00057 extern int _cpio_debug;
00058
00059
00060 extern int _fps_debug;
00061
00062
00063 extern int _fsm_debug;
00064
00065
00066 extern int _fsm_threads;
00067
00068
00069 extern int _hdr_debug;
00070
00071
00072 extern int _mire_debug;
00073
00074
00075 extern int _print_pkts;
00076
00077
00078 extern int _psm_debug;
00079
00080
00081 extern int _psm_threads;
00082
00083
00084 extern int _rpmal_debug;
00085
00086
00087 extern int _rpmdb_debug;
00088
00089
00090 extern int _rpmds_debug;
00091
00092
00093
00094 int _rpmfc_debug;
00095
00096
00097 extern int _rpmfi_debug;
00098
00099
00100 extern int _rpmgi_debug;
00101
00102
00103 extern int _rpmmg_debug;
00104
00105
00106 extern int _rpmps_debug;
00107
00108
00109 extern int _rpmsq_debug;
00110
00111
00112 extern int _rpmsx_debug;
00113
00114
00115 extern int _rpmte_debug;
00116
00117
00118 extern int _rpmts_debug;
00119
00120
00121 extern int _rpmwf_debug;
00122
00123
00124 extern int _xar_debug;
00125
00126
00127 extern int _rpmts_macros;
00128
00129
00130 extern int _rpmts_stats;
00131
00132
00133 extern int _hdr_stats;
00134
00135
00136 extern int _tar_debug;
00137
00138
00139 extern int noLibio;
00140
00141
00142
00143 const char * rpmcliPipeOutput = NULL;
00144
00145
00146 const char * rpmcliRootDir = "/";
00147
00148
00149 rpmQueryFlags rpmcliQueryFlags;
00150
00151
00152 const char * rpmcliTargets = NULL;
00153
00154
00155
00156 extern int _ftp_debug;
00157
00158 extern int _av_debug;
00159
00160 extern int _dav_debug;
00161
00162
00163 extern int noLibio;
00164
00165
00166 extern int _rpmio_debug;
00167
00168
00169
00170 static int rpmcliInitialized = -1;
00171
00175 static void printVersion(FILE * fp)
00176
00177
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
00187
00188
00189
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 enum poptCallbackReason reason,
00211 const struct poptOption * opt, const char * arg,
00212 const void * data)
00213
00214
00215
00216
00217 {
00218
00219
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
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
00243
00244 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
00245 (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
00246
00247 s = _free(s);
00248 } break;
00249 case POPT_UNDEFINE:
00250 { char *s, *t;
00251
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
00260 rpmcliConfigured();
00261 (void) rpmUndefineMacro(NULL, t);
00262 (void) rpmUndefineMacro(rpmCLIMacroContext, t);
00263
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)
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 con = rpmcliFini(con);
00305 exit(EXIT_SUCCESS);
00306 break;
00307 case POPT_SHOWRC:
00308 rpmcliConfigured();
00309 (void) rpmShowRC(stdout);
00310 con = rpmcliFini(con);
00311 exit(EXIT_SUCCESS);
00312 break;
00313 case POPT_QUERYTAGS:
00314 rpmDisplayQueryTags(NULL, NULL, NULL);
00315 con = rpmcliFini(con);
00316 exit(EXIT_SUCCESS);
00317 break;
00318 #if defined(POPT_RCFILE)
00319 case POPT_RCFILE:
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
00342 char * t = (char *) rpmcliTargets;
00343 size_t nb = strlen(t) + (sizeof(",")-1) + strlen(arg) + 1;
00344 t = xrealloc(t, nb);
00345 (void) stpcpy( stpcpy(t, ","), arg);
00346 rpmcliTargets = t;
00347
00348 }
00349 break;
00350 }
00351 }
00352
00353
00354 int ftsOpts = 0;
00355
00356
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
00378 int global_depFlags;
00379
00380
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
00415
00416 struct poptOption rpmcliAllPoptTable[] = {
00417
00418 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00419 rpmcliAllArgCallback, 0, NULL, NULL },
00420
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
00556
00557 poptContext
00558 rpmcliFini(poptContext optCon)
00559 {
00560
00561
00562 rpmFreeMacros(NULL);
00563 rpmFreeMacros(rpmCLIMacroContext);
00564
00565 rpmioClean();
00566
00567 rpmnsClean();
00568
00569 rpmFreeRpmrc();
00570
00571 rpmFreeFilesystems();
00572 rpmcliTargets = _free(rpmcliTargets);
00573
00574 keyids = _free(keyids);
00575
00576 tagClean(NULL);
00577
00578 optCon = poptFreeContext(optCon);
00579
00580 #if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
00581
00582 muntrace();
00583
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
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
00609 mtrace();
00610
00611 #endif
00612
00613 setprogname(argv[0]);
00614
00615
00616 if (__progname == NULL) {
00617 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00618 else __progname = argv[0];
00619 }
00620
00621
00622
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
00645 rpmcliConfigured();
00646 return NULL;
00647 }
00648
00649
00650 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00651
00652
00653
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
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)
00667 if (path[0] == '@' ) {
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
00677 ac = 0;
00678 av = NULL;
00679 if ((i = rpmGlob(path, &ac, &av)) != 0)
00680 continue;
00681
00682
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
00692 (void) poptReadDefaultConfig(optCon, 1);
00693
00694 poptSetExecPath(optCon, USRLIBRPM, 1);
00695
00696
00697 while ((rc = poptGetNextOpt(optCon)) > 0) {
00698 const char * optArg = poptGetOptArg(optCon);
00699 optArg = _free(optArg);
00700 switch (rc) {
00701 default:
00702
00703 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00704 __progname, rc);
00705
00706 exit(EXIT_FAILURE);
00707
00708 break;
00709 }
00710 }
00711
00712 if (rc < -1) {
00713
00714 fprintf(stderr, "%s: %s: %s\n", __progname,
00715 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00716 poptStrerror(rc));
00717
00718 exit(EXIT_FAILURE);
00719 }
00720
00721
00722 rpmcliConfigured();
00723
00724 if (_debug) {
00725 rpmIncreaseVerbosity();
00726 rpmIncreaseVerbosity();
00727 }
00728
00729
00730
00731 _hdr_stats = _rpmts_stats;
00732
00733
00734 return optCon;
00735 }
00736