3 * Popt tables for all rpm modes.
7 const char *__progname;
9 #include <rpm/rpmcli.h>
10 #include <rpm/rpmgi.h>
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmstring.h>
16 #define POPT_SHOWVERSION -999
17 #define POPT_SHOWRC -998
18 #define POPT_QUERYTAGS -997
19 #define POPT_PREDEFINE -996
21 #define POPT_RCFILE -995
24 static int _debug = 0;
26 extern int _rpmds_nopromote;
28 extern int _fps_debug;
30 extern int _fsm_debug;
32 extern int _fsm_threads;
34 extern int _hdr_debug;
36 extern int _print_pkts;
38 extern int _psm_debug;
40 extern int _psm_threads;
42 extern int _rpmal_debug;
44 extern int _rpmdb_debug;
46 extern int _rpmds_debug;
48 /* XXX avoid -lrpmbuild linkage. */
51 extern int _rpmfi_debug;
53 extern int _rpmgi_debug;
55 extern int _rpmps_debug;
57 extern int _rpmsq_debug;
59 extern int _rpmte_debug;
61 extern int _rpmts_debug;
63 extern int _rpmts_stats;
67 const char * rpmcliPipeOutput = NULL;
69 const char * rpmcliRcfile = NULL;
71 const char * rpmcliRootDir = "/";
73 rpmQueryFlags rpmcliQueryFlags;
77 extern int _rpmio_debug;
79 static int rpmcliInitialized = -1;
82 * Display rpm version.
84 static void printVersion(FILE * fp)
86 fprintf(fp, _("RPM version %s\n"), rpmEVR);
90 * Make sure that config files have been read.
91 * @warning Options like --rcfile and --verbose must precede callers option.
93 void rpmcliConfigured(void)
96 if (rpmcliInitialized < 0)
97 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
98 if (rpmcliInitialized)
104 static void rpmcliAllArgCallback( poptContext con,
105 enum poptCallbackReason reason,
106 const struct poptOption * opt, const char * arg,
110 /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
111 if (opt->arg == NULL)
114 rpmSetVerbosity(RPMLOG_WARNING);
117 rpmIncreaseVerbosity();
120 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
124 /* XXX Convert '-' in macro name to underscore, skip leading %. */
125 s = t = xstrdup(arg);
126 while (*t && !xisspace(*t)) {
127 if (*t == '-') *t = '_';
132 /* XXX Predefine macro if not initialized yet. */
133 if (rpmcliInitialized < 0)
134 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
136 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
137 (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
143 { char *val = rpmExpand(arg, NULL);
144 fprintf(stdout, "%s\n", val);
148 case POPT_SHOWVERSION:
149 printVersion(stdout);
154 (void) rpmShowRC(stdout);
158 rpmDisplayQueryTags(stdout);
161 #if defined(POPT_RCFILE)
162 case POPT_RCFILE: /* XXX FIXME: noop for now */
165 case RPMCLI_POPT_NODIGEST:
166 rpmcliQueryFlags |= VERIFY_DIGEST;
169 case RPMCLI_POPT_NOSIGNATURE:
170 rpmcliQueryFlags |= VERIFY_SIGNATURE;
173 case RPMCLI_POPT_NOHDRCHK:
174 rpmcliQueryFlags |= VERIFY_HDRCHK;
181 struct poptOption rpmcliFtsPoptTable[] = {
182 { "comfollow", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_COMFOLLOW,
183 N_("RPMGI_COMFOLLOW: follow command line symlinks"), NULL },
184 { "logical", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_LOGICAL,
185 N_("RPMGI_LOGICAL: logical walk"), NULL },
186 { "nochdir", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_NOCHDIR,
187 N_("RPMGI_NOCHDIR: don't change directories"), NULL },
188 { "nostat", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_NOSTAT,
189 N_("RPMGI_NOSTAT: don't get stat info"), NULL },
190 { "physical", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_PHYSICAL,
191 N_("RPMGI_PHYSICAL: physical walk"), NULL },
192 { "seedot", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_SEEDOT,
193 N_("RPMGI_SEEDOT: return dot and dot-dot"), NULL },
194 { "xdev", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_XDEV,
195 N_("RPMGI_XDEV: don't cross devices"), NULL },
196 { "whiteout", '\0', POPT_BIT_SET, &ftsOpts, RPMGI_WHITEOUT,
197 N_("RPMGI_WHITEOUT: return whiteout information"), NULL },
201 struct poptOption rpmcliAllPoptTable[] = {
203 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
204 rpmcliAllArgCallback, 0, NULL, NULL },
206 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
209 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
210 N_("predefine MACRO with value EXPR"),
211 N_("'MACRO EXPR'") },
212 { "define", 'D', POPT_ARG_STRING, 0, 'D',
213 N_("define MACRO with value EXPR"),
214 N_("'MACRO EXPR'") },
215 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
216 N_("print macro expansion of EXPR"),
218 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
219 N_("read <FILE:...> instead of default file(s)"),
222 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
223 N_("don't verify package digest(s)"), NULL },
224 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
225 N_("don't verify database header(s) when retrieved"), NULL },
226 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
227 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
228 N_("disable use of libio(3) API"), NULL},
230 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
231 N_("don't verify package signature(s)"), NULL },
233 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
234 N_("send stdout to CMD"),
236 #if !defined(POPT_RCFILE)
237 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
238 N_("read <FILE:...> instead of default file(s)"),
241 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
242 N_("read <FILE:...> instead of default file(s)"),
245 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
246 N_("use ROOT as top level directory"),
249 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
250 N_("display known query tags"), NULL },
251 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
252 N_("display final rpmrc and macro configuration"), NULL },
253 { "quiet", '\0', 0, NULL, 'q',
254 N_("provide less detailed output"), NULL},
255 { "verbose", 'v', 0, NULL, 'v',
256 N_("provide more detailed output"), NULL},
257 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
258 N_("print the version of rpm being used"), NULL },
260 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
261 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
262 N_("disable use of libio(3) API"), NULL},
265 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
268 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
270 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
271 N_("debug payload file state machine"), NULL},
272 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
273 N_("use threads for file state machine"), NULL},
274 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
277 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
278 N_("debug option/argument processing"), NULL},
280 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
282 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
283 N_("debug package state machine"), NULL},
284 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
285 N_("use threads for package state machine"), NULL},
286 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
288 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
290 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
292 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
294 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
296 { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
298 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
299 N_("debug rpmio I/O"), NULL},
300 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
302 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
304 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
306 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
308 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
310 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
311 N_("debug URL cache handling"), NULL},
317 rpmcliFini(poptContext optCon)
319 optCon = poptFreeContext(optCon);
321 #if HAVE_MCHECK_H && HAVE_MTRACE
322 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
329 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
335 #if HAVE_MCHECK_H && HAVE_MTRACE
336 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
338 setprogname(argv[0]); /* Retrofit glibc __progname */
340 /* XXX glibc churn sanity */
341 if (__progname == NULL) {
342 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
343 else __progname = argv[0];
346 #if defined(ENABLE_NLS)
347 (void) setlocale(LC_ALL, "" );
349 (void) bindtextdomain(PACKAGE, LOCALEDIR);
350 (void) textdomain(PACKAGE);
353 rpmSetVerbosity(RPMLOG_NOTICE);
355 if (optionsTable == NULL) {
356 /* Read rpm configuration (if not already read). */
361 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
362 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
363 #if RPM_USES_POPTREADDEFAULTCONFIG
364 (void) poptReadDefaultConfig(optCon, 1);
366 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
368 /* Process all options, whine if unknown. */
369 while ((rc = poptGetNextOpt(optCon)) > 0) {
370 optArg = poptGetOptArg(optCon);
373 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
382 fprintf(stderr, "%s: %s: %s\n", __progname,
383 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
388 /* Read rpm configuration (if not already read). */
392 rpmIncreaseVerbosity();
393 rpmIncreaseVerbosity();