Argh. Realize we already have equivalents of initCli() and finishCli()
- rpmcliInit() and rpmcliFini() do almost exactly the same as our newborn cli-helpers, but they've been almost unused until now. Use them and lose the new ones.. doh. - The downside is that popt aliases are now broken when running commands from the build tree due to lt-foo in argv[0], whereas initCli() took and explicit popt context name argument. Oh well... - rpmcliFini() was missing several necessary memory cleanup calls, add them there while at it.
This commit is contained in:
parent
e951c42146
commit
fbd92df754
71
cliutils.c
71
cliutils.c
|
@ -44,77 +44,6 @@ void printUsage(poptContext con, FILE * fp, int flags)
|
|||
poptPrintUsage(con, fp, flags);
|
||||
}
|
||||
|
||||
poptContext initCli(const char *ctx, struct poptOption *optionsTable,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
const char *optArg;
|
||||
int arg;
|
||||
poptContext optCon;
|
||||
|
||||
#if HAVE_MCHECK_H && HAVE_MTRACE
|
||||
mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_NLS)
|
||||
/* set up the correct locale */
|
||||
(void) setlocale(LC_ALL, "" );
|
||||
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
#endif
|
||||
|
||||
rpmSetVerbosity(RPMLOG_NOTICE); /* XXX silly use by showrc */
|
||||
|
||||
/* Make a first pass through the arguments, looking for --rcfile */
|
||||
/* We need to handle that before dealing with the rest of the arguments. */
|
||||
/* XXX popt argv definition should be fixed instead of casting... */
|
||||
optCon = poptGetContext(ctx, argc, (const char **)argv, optionsTable, 0);
|
||||
{
|
||||
char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL);
|
||||
(void) poptReadConfigFile(optCon, poptfile);
|
||||
free(poptfile);
|
||||
}
|
||||
(void) poptReadDefaultConfig(optCon, 1);
|
||||
poptSetExecPath(optCon, rpmConfigDir(), 1);
|
||||
|
||||
while ((arg = poptGetNextOpt(optCon)) > 0) {
|
||||
optArg = poptGetOptArg(optCon);
|
||||
|
||||
switch (arg) {
|
||||
default:
|
||||
fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (arg < -1) {
|
||||
fprintf(stderr, "%s: %s\n",
|
||||
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(arg));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
rpmcliConfigured();
|
||||
|
||||
return optCon;
|
||||
}
|
||||
|
||||
int finishCli(poptContext optCon, int rc)
|
||||
{
|
||||
poptFreeContext(optCon);
|
||||
rpmFreeMacros(NULL);
|
||||
rpmFreeMacros(rpmCLIMacroContext);
|
||||
rpmFreeRpmrc();
|
||||
rpmlogClose();
|
||||
|
||||
#if HAVE_MCHECK_H && HAVE_MTRACE
|
||||
muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
|
||||
#endif
|
||||
|
||||
/* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */
|
||||
return (rc > 254) ? 254 : rc;
|
||||
}
|
||||
|
||||
int initPipe(void)
|
||||
{
|
||||
int p[2];
|
||||
|
|
10
cliutils.h
10
cliutils.h
|
@ -5,18 +5,14 @@
|
|||
#include <popt.h>
|
||||
#include <rpm/rpmutil.h>
|
||||
|
||||
/* "normalized" exit: avoid overflowing and xargs special value 255 */
|
||||
#define RETVAL(rc) (((rc) > 254) ? 254 : (rc))
|
||||
|
||||
RPM_GNUC_NORETURN
|
||||
void argerror(const char * desc);
|
||||
|
||||
void printUsage(poptContext con, FILE * fp, int flags);
|
||||
|
||||
/* Initialize cli-environment, returning parsed popt context caller */
|
||||
poptContext initCli(const char *ctx, struct poptOption *optionsTable,
|
||||
int argc, char *argv[]);
|
||||
|
||||
/* Free up common resources, return "normalized" exit code */
|
||||
int finishCli(poptContext optCon, int rc);
|
||||
|
||||
int initPipe(void);
|
||||
|
||||
void finishPipe(void);
|
||||
|
|
|
@ -230,7 +230,11 @@ struct poptOption rpmcliAllPoptTable[] = {
|
|||
poptContext
|
||||
rpmcliFini(poptContext optCon)
|
||||
{
|
||||
optCon = poptFreeContext(optCon);
|
||||
poptFreeContext(optCon);
|
||||
rpmFreeMacros(NULL);
|
||||
rpmFreeMacros(rpmCLIMacroContext);
|
||||
rpmFreeRpmrc();
|
||||
rpmlogClose();
|
||||
|
||||
#if HAVE_MCHECK_H && HAVE_MTRACE
|
||||
muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
|
||||
|
|
16
rpmbuild.c
16
rpmbuild.c
|
@ -386,18 +386,8 @@ int main(int argc, char *argv[])
|
|||
char * passPhrase = "";
|
||||
|
||||
const char *pkg = NULL;
|
||||
poptContext optCon;
|
||||
int ec = 0;
|
||||
|
||||
setprogname(argv[0]); /* Retrofit glibc __progname */
|
||||
|
||||
/* XXX glibc churn sanity */
|
||||
if (__progname == NULL) {
|
||||
if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
|
||||
else __progname = argv[0];
|
||||
}
|
||||
|
||||
optCon = initCli("rpmbuild", optionsTable, argc, argv);
|
||||
poptContext optCon = rpmcliInit(argc, argv, optionsTable);
|
||||
|
||||
if (argc <= 1 || poptPeekArg(optCon) == NULL) {
|
||||
printUsage(optCon, stderr, 0);
|
||||
|
@ -534,5 +524,7 @@ exit:
|
|||
ba->buildRootOverride = _free(ba->buildRootOverride);
|
||||
ba->targets = _free(ba->targets);
|
||||
|
||||
return finishCli(optCon, ec);
|
||||
rpmcliFini(optCon);
|
||||
|
||||
return RETVAL(ec);
|
||||
}
|
||||
|
|
14
rpmqv.c
14
rpmqv.c
|
@ -123,15 +123,7 @@ int main(int argc, char *argv[])
|
|||
int i;
|
||||
#endif
|
||||
|
||||
setprogname(argv[0]); /* Retrofit glibc __progname */
|
||||
|
||||
/* XXX glibc churn sanity */
|
||||
if (__progname == NULL) {
|
||||
if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
|
||||
else __progname = argv[0];
|
||||
}
|
||||
|
||||
optCon = initCli("rpm", optionsTable, argc, argv);
|
||||
optCon = rpmcliInit(argc, argv, optionsTable);
|
||||
|
||||
/* Set the major mode based on argv[0] */
|
||||
#ifdef IAM_RPMQV
|
||||
|
@ -547,5 +539,7 @@ exit:
|
|||
ia->relocations = _free(ia->relocations);
|
||||
#endif
|
||||
|
||||
return finishCli(optCon, ec);
|
||||
rpmcliFini(optCon);
|
||||
|
||||
return RETVAL(ec);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue