3 * Popt tables for all rpm modes.
7 const char *__progname;
14 #define POPT_SHOWVERSION -999
15 #define POPT_SHOWRC -998
16 #define POPT_QUERYTAGS -997
17 #define POPT_PREDEFINE -996
19 #define POPT_RCFILE -995
23 static int _debug = 0;
25 /*@-exportheadervar@*/
27 extern int _rpmds_nopromote;
30 extern int _fps_debug;
33 extern int _fsm_debug;
36 extern int _fsm_threads;
39 extern int _hdr_debug;
42 extern int _print_pkts;
45 extern int _psm_debug;
48 extern int _psm_threads;
51 extern int _rpmal_debug;
54 extern int _rpmdb_debug;
57 extern int _rpmds_debug;
59 /* XXX avoid -lrpmbuild linkage. */
64 extern int _rpmfi_debug;
67 extern int _rpmgi_debug;
70 extern int _rpmps_debug;
73 extern int _rpmsq_debug;
76 extern int _rpmte_debug;
79 extern int _rpmts_debug;
82 extern int _rpmts_stats;
86 /*@=exportheadervar@*/
89 const char * rpmcliPipeOutput = NULL;
92 const char * rpmcliRcfile = NULL;
95 const char * rpmcliRootDir = "/";
98 rpmQueryFlags rpmcliQueryFlags;
100 /*@-exportheadervar@*/
102 extern int _ftp_debug;
104 extern int _av_debug;
106 extern int _dav_debug;
112 extern int _rpmio_debug;
113 /*@=exportheadervar@*/
116 static int rpmcliInitialized = -1;
119 * Display rpm version.
121 static void printVersion(FILE * fp)
122 /*@globals rpmEVR, fileSystem @*/
123 /*@modifies *fp, fileSystem @*/
125 fprintf(fp, _("RPM version %s\n"), rpmEVR);
129 * Make sure that config files have been read.
130 * @warning Options like --rcfile and --verbose must precede callers option.
133 void rpmcliConfigured(void)
134 /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
135 h_errno, fileSystem, internalState @*/
136 /*@modifies rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
137 fileSystem, internalState @*/
140 if (rpmcliInitialized < 0)
141 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
142 if (rpmcliInitialized)
149 static void rpmcliAllArgCallback( /*@unused@*/ poptContext con,
150 /*@unused@*/ enum poptCallbackReason reason,
151 const struct poptOption * opt, const char * arg,
152 /*@unused@*/ const void * data)
153 /*@globals rpmcliQueryFlags, rpmCLIMacroContext, rpmGlobalMacroContext,
154 h_errno, fileSystem, internalState @*/
155 /*@modifies rpmcliQueryFlags, rpmCLIMacroContext, rpmGlobalMacroContext,
156 fileSystem, internalState @*/
159 /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
161 if (opt->arg == NULL)
164 rpmSetVerbosity(RPMMESS_QUIET);
167 rpmIncreaseVerbosity();
170 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
173 /* XXX Predefine macro if not initialized yet. */
174 if (rpmcliInitialized < 0)
175 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
178 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
179 (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
184 { const char *val = rpmExpand(arg, NULL);
185 fprintf(stdout, "%s\n", val);
189 case POPT_SHOWVERSION:
190 printVersion(stdout);
192 /*@notreached@*/ break;
195 (void) rpmShowRC(stdout);
197 /*@notreached@*/ break;
199 rpmDisplayQueryTags(stdout);
201 /*@notreached@*/ break;
202 #if defined(POPT_RCFILE)
203 case POPT_RCFILE: /* XXX FIXME: noop for now */
206 case RPMCLI_POPT_NODIGEST:
207 rpmcliQueryFlags |= VERIFY_DIGEST;
210 case RPMCLI_POPT_NOSIGNATURE:
211 rpmcliQueryFlags |= VERIFY_SIGNATURE;
214 case RPMCLI_POPT_NOHDRCHK:
215 rpmcliQueryFlags |= VERIFY_HDRCHK;
225 struct poptOption rpmcliFtsPoptTable[] = {
226 { "comfollow", '\0', POPT_BIT_SET, &ftsOpts, FTS_COMFOLLOW,
227 N_("FTS_COMFOLLOW: follow command line symlinks"), NULL },
228 { "logical", '\0', POPT_BIT_SET, &ftsOpts, FTS_LOGICAL,
229 N_("FTS_LOGICAL: logical walk"), NULL },
230 { "nochdir", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOCHDIR,
231 N_("FTS_NOCHDIR: don't change directories"), NULL },
232 { "nostat", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOSTAT,
233 N_("FTS_NOSTAT: don't get stat info"), NULL },
234 { "physical", '\0', POPT_BIT_SET, &ftsOpts, FTS_PHYSICAL,
235 N_("FTS_PHYSICAL: physical walk"), NULL },
236 { "seedot", '\0', POPT_BIT_SET, &ftsOpts, FTS_SEEDOT,
237 N_("FTS_SEEDOT: return dot and dot-dot"), NULL },
238 { "xdev", '\0', POPT_BIT_SET, &ftsOpts, FTS_XDEV,
239 N_("FTS_XDEV: don't cross devices"), NULL },
240 { "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT,
241 N_("FTS_WHITEOUT: return whiteout information"), NULL },
245 /*@-bitwisesigned -compmempass @*/
247 struct poptOption rpmcliAllPoptTable[] = {
248 /*@-type@*/ /* FIX: cast? */
249 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
250 rpmcliAllArgCallback, 0, NULL, NULL },
253 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
256 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
257 N_("predefine MACRO with value EXPR"),
258 N_("'MACRO EXPR'") },
259 { "define", 'D', POPT_ARG_STRING, 0, 'D',
260 N_("define MACRO with value EXPR"),
261 N_("'MACRO EXPR'") },
262 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
263 N_("print macro expansion of EXPR"),
265 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
266 N_("read <FILE:...> instead of default file(s)"),
269 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
270 N_("don't verify package digest(s)"), NULL },
271 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
272 N_("don't verify database header(s) when retrieved"), NULL },
273 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
274 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
275 N_("disable use of libio(3) API"), NULL},
277 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
278 N_("don't verify package signature(s)"), NULL },
280 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
281 N_("send stdout to CMD"),
283 #if !defined(POPT_RCFILE)
284 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
285 N_("read <FILE:...> instead of default file(s)"),
288 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
289 N_("read <FILE:...> instead of default file(s)"),
292 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
293 N_("use ROOT as top level directory"),
296 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
297 N_("display known query tags"), NULL },
298 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
299 N_("display final rpmrc and macro configuration"), NULL },
300 { "quiet", '\0', 0, NULL, 'q',
301 N_("provide less detailed output"), NULL},
302 { "verbose", 'v', 0, NULL, 'v',
303 N_("provide more detailed output"), NULL},
304 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
305 N_("print the version of rpm being used"), NULL },
307 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
308 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
309 N_("disable use of libio(3) API"), NULL},
312 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
315 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
317 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
318 N_("debug payload file state machine"), NULL},
319 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
320 N_("use threads for file state machine"), NULL},
321 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
322 N_("debug FTP/HTTP data stream"), NULL},
323 { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1,
324 N_("debug argv collections"), NULL},
325 { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1,
326 N_("debug WebDAV data stream"), NULL},
327 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
330 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
331 N_("debug option/argument processing"), NULL},
333 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
335 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
336 N_("debug package state machine"), NULL},
337 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
338 N_("use threads for package state machine"), NULL},
339 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
341 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
343 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
345 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
347 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
349 { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
351 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
352 N_("debug rpmio I/O"), NULL},
353 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
355 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
357 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
359 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
361 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
363 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
364 N_("debug URL cache handling"), NULL},
368 /*@=bitwisesigned =compmempass @*/
371 rpmcliFini(poptContext optCon)
373 optCon = poptFreeContext(optCon);
375 #if HAVE_MCHECK_H && HAVE_MTRACE
377 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
386 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
392 #if HAVE_MCHECK_H && HAVE_MTRACE
394 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
398 setprogname(argv[0]); /* Retrofit glibc __progname */
400 /* XXX glibc churn sanity */
401 if (__progname == NULL) {
402 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
403 else __progname = argv[0];
407 #if defined(ENABLE_NLS)
408 (void) setlocale(LC_ALL, "" );
409 (void) bindtextdomain(PACKAGE, LOCALEDIR);
410 (void) textdomain(PACKAGE);
413 rpmSetVerbosity(RPMMESS_NORMAL);
415 if (optionsTable == NULL) {
416 /* Read rpm configuration (if not already read). */
421 /*@-nullpass -temptrans@*/
422 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
423 /*@=nullpass =temptrans@*/
424 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
425 (void) poptReadDefaultConfig(optCon, 1);
426 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
428 /* Process all options, whine if unknown. */
429 while ((rc = poptGetNextOpt(optCon)) > 0) {
430 optArg = poptGetOptArg(optCon);
434 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
439 /*@notreached@*/ /*@switchbreak@*/ break;
445 fprintf(stderr, "%s: %s: %s\n", __progname,
446 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
452 /* Read rpm configuration (if not already read). */
456 rpmIncreaseVerbosity();
457 rpmIncreaseVerbosity();