summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-08-20 15:17:08 +0300
committerPanu Matilainen <pmatilai@redhat.com>2010-08-20 15:23:48 +0300
commitfbd92df7544462a88cd8c752ffe07263dc8bb858 (patch)
treee6e2f009714b930ca8cd7371a9aa62fbc9334834
parente951c42146d89a5f4abdb02eaf9e44eead235e2f (diff)
downloadrpm-fbd92df7544462a88cd8c752ffe07263dc8bb858.tar.gz
rpm-fbd92df7544462a88cd8c752ffe07263dc8bb858.tar.bz2
rpm-fbd92df7544462a88cd8c752ffe07263dc8bb858.zip
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.
-rw-r--r--cliutils.c71
-rw-r--r--cliutils.h10
-rw-r--r--lib/poptALL.c6
-rw-r--r--rpmbuild.c16
-rw-r--r--rpmqv.c14
5 files changed, 16 insertions, 101 deletions
diff --git a/cliutils.c b/cliutils.c
index 23c632372..cbbc7fef2 100644
--- a/cliutils.c
+++ b/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];
diff --git a/cliutils.h b/cliutils.h
index ea4539899..875b9507c 100644
--- a/cliutils.h
+++ b/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);
diff --git a/lib/poptALL.c b/lib/poptALL.c
index 796675608..1ad95ea76 100644
--- a/lib/poptALL.c
+++ b/lib/poptALL.c
@@ -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. */
diff --git a/rpmbuild.c b/rpmbuild.c
index b7cfbbd08..da04289ff 100644
--- a/rpmbuild.c
+++ b/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);
}
diff --git a/rpmqv.c b/rpmqv.c
index e9e23ee3e..8d4bdf0f0 100644
--- a/rpmqv.c
+++ b/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);
}