summaryrefslogtreecommitdiff
path: root/rpmqv.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-08-20 13:16:48 +0300
committerPanu Matilainen <pmatilai@redhat.com>2010-08-20 13:50:48 +0300
commit03a8511e3ba8b2c6cf3dc67fadaeca4aa9fb5221 (patch)
treec796c19f884bd3f660e192e7e4745c835a77eb93 /rpmqv.c
parentb217529967f972225dc9b7d2e37860885fde1ee1 (diff)
downloadlibrpm-tizen-03a8511e3ba8b2c6cf3dc67fadaeca4aa9fb5221.tar.gz
librpm-tizen-03a8511e3ba8b2c6cf3dc67fadaeca4aa9fb5221.tar.bz2
librpm-tizen-03a8511e3ba8b2c6cf3dc67fadaeca4aa9fb5221.zip
Lump much of the common cli-init + finish tasks into cliutils helpers
Diffstat (limited to 'rpmqv.c')
-rw-r--r--rpmqv.c76
1 files changed, 4 insertions, 72 deletions
diff --git a/rpmqv.c b/rpmqv.c
index dd6b86380..4897eece0 100644
--- a/rpmqv.c
+++ b/rpmqv.c
@@ -4,15 +4,10 @@ const char *__progname;
#define _AUTOHELP
#include <sys/wait.h>
-#if HAVE_MCHECK_H
-#include <mcheck.h>
-#endif
-
#include <rpm/rpmcli.h>
#include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
#include <rpm/rpmbuild.h>
#include <rpm/rpmlog.h>
-#include <rpm/rpmfileutil.h>
#include <rpm/rpmdb.h>
#include <rpm/rpmps.h>
#include <rpm/rpmts.h>
@@ -123,9 +118,6 @@ int main(int argc, char *argv[])
char * passPhrase = "";
#endif
- int arg;
-
- const char *optArg, *poptCtx;
pid_t pipeChild = 0;
poptContext optCon;
int ec = 0;
@@ -134,10 +126,7 @@ int main(int argc, char *argv[])
#ifdef IAM_RPMEIU
int i;
#endif
-
-#if HAVE_MCHECK_H && HAVE_MTRACE
- mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
-#endif
+
setprogname(argv[0]); /* Retrofit glibc __progname */
/* XXX glibc churn sanity */
@@ -146,6 +135,8 @@ int main(int argc, char *argv[])
else __progname = argv[0];
}
+ optCon = initCli("rpm", optionsTable, argc, argv);
+
/* Set the major mode based on argv[0] */
#ifdef IAM_RPMQV
if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY;
@@ -170,50 +161,6 @@ int main(int argc, char *argv[])
}
#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 */
-
- /* Only build has it's own set of aliases, everything else uses rpm */
- poptCtx = "rpm";
-
- /* 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(poptCtx, 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();
-
#ifdef IAM_RPMDB
if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
if (da->init) {
@@ -610,19 +557,11 @@ exit:
ts = rpmtsFree(ts);
- optCon = poptFreeContext(optCon);
- rpmFreeMacros(NULL);
- rpmFreeMacros(rpmCLIMacroContext);
- rpmFreeRpmrc();
-
if (pipeChild) {
(void) fclose(stdout);
(void) waitpid(pipeChild, &status, 0);
}
- /* keeps memory leak checkers quiet */
- rpmlogClose();
-
#ifdef IAM_RPMQV
qva->qva_queryFormat = _free(qva->qva_queryFormat);
#endif
@@ -634,12 +573,5 @@ exit:
ia->relocations = _free(ia->relocations);
#endif
-#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) */
- if (ec > 254) ec = 254;
-
- return ec;
+ return finishCli(optCon, ec);
}