X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=rpmqv.c;h=da5f2ca1328384026b383e35ba756611a37a75a4;hb=9e5a78eb23d569cc4beb961b8e5f724f1695ed59;hp=cd8f2ee4f97b5efe2d291c61ba1bcf74d2c0212e;hpb=43b08986a8aa0464566716f6fe0d510e96cd77bf;p=platform%2Fupstream%2Frpm.git diff --git a/rpmqv.c b/rpmqv.c index cd8f2ee..da5f2ca 100644 --- a/rpmqv.c +++ b/rpmqv.c @@ -1,38 +1,20 @@ #include "system.h" const char *__progname; -#define _AUTOHELP - -#if defined(IAM_RPM) -#define IAM_RPMBT -#define IAM_RPMDB -#define IAM_RPMEIU -#define IAM_RPMQV -#define IAM_RPMK -#endif - #include #include /* RPMSIGTAG, rpmReadPackageFile .. */ -#include #include -#include - -#include #include #include -#ifdef IAM_RPMBT -#include "build.h" -#define GETOPT_REBUILD 1003 -#define GETOPT_RECOMPILE 1004 -#endif - -#if defined(IAM_RPMBT) || defined(IAM_RPMK) -#include "lib/signature.h" -#endif +#include "cliutils.h" #include "debug.h" +#if defined(IAM_RPMQ) || defined(IAM_RPMV) +#define IAM_RPMQV +#endif + enum modes { MODE_QUERY = (1 << 0), @@ -43,29 +25,11 @@ enum modes { MODE_ERASE = (1 << 2), #define MODES_IE (MODE_INSTALL | MODE_ERASE) - MODE_BUILD = (1 << 4), - MODE_REBUILD = (1 << 5), - MODE_RECOMPILE = (1 << 8), - MODE_TARBUILD = (1 << 11), -#define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE) - - MODE_CHECKSIG = (1 << 6), - MODE_RESIGN = (1 << 7), -#define MODES_K (MODE_CHECKSIG | MODE_RESIGN) - - MODE_INITDB = (1 << 10), - MODE_REBUILDDB = (1 << 12), - MODE_VERIFYDB = (1 << 13), -#define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB) - - MODE_UNKNOWN = 0 }; -#define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB) -#define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY) -#define MODES_FOR_TEST (MODES_BT | MODES_IE) -#define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB | MODES_K) +#define MODES_FOR_NODEPS (MODES_IE | MODE_VERIFY) +#define MODES_FOR_TEST (MODES_IE) static int quiet; @@ -73,39 +37,20 @@ static int quiet; static struct poptOption optionsTable[] = { #ifdef IAM_RPMQV + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0, + N_("Query/Verify package selection options:"), + NULL }, +#endif +#ifdef IAM_RPMQ { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0, N_("Query options (with -q or --query):"), NULL }, +#endif +#ifdef IAM_RPMV { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0, N_("Verify options (with -V or --verify):"), NULL }, -#ifdef NOTYET - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliQVSourcePoptTable, 0, - N_("Source options (with --query or --verify):"), - NULL }, #endif - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliFtsPoptTable, 0, - N_("File tree walk options (with --ftswalk):"), - NULL }, -#endif /* IAM_RPMQV */ - -#ifdef IAM_RPMK - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0, - N_("Signature options:"), - NULL }, -#endif /* IAM_RPMK */ - -#ifdef IAM_RPMDB - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0, - N_("Database options:"), - NULL }, -#endif /* IAM_RPMDB */ - -#ifdef IAM_RPMBT - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0, - N_("Build options with [ | | ]:"), - NULL }, -#endif /* IAM_RPMBT */ #ifdef IAM_RPMEIU { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0, @@ -113,7 +58,7 @@ static struct poptOption optionsTable[] = { NULL }, #endif /* IAM_RPMEIU */ - { "quiet", '\0', 0, &quiet, 0, NULL, NULL}, + { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, NULL}, { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0, N_("Common options for all rpm modes and executables:"), @@ -124,40 +69,6 @@ static struct poptOption optionsTable[] = { POPT_TABLEEND }; -#ifdef __MINT__ -/* MiNT cannot dynamically increase the stack. */ -long _stksize = 64 * 1024L; -#endif - -static void argerror(const char * desc) -{ - fprintf(stderr, _("%s: %s\n"), __progname, desc); - exit(EXIT_FAILURE); -} - -static void printVersion(FILE * fp) -{ - fprintf(fp, _("RPM version %s\n"), rpmEVR); -} - -static void printBanner(FILE * fp) -{ - fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n")); - fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n")); -} - -static void printUsage(poptContext con, FILE * fp, int flags) -{ - printVersion(fp); - printBanner(fp); - fprintf(fp, "\n"); - - if (rpmIsVerbose()) - poptPrintHelp(con, fp, flags); - else - poptPrintUsage(con, fp, flags); -} - int main(int argc, char *argv[]) { rpmts ts = NULL; @@ -167,56 +78,22 @@ int main(int argc, char *argv[]) QVA_t qva = &rpmQVKArgs; #endif -#ifdef IAM_RPMBT - BTA_t ba = &rpmBTArgs; -#endif - #ifdef IAM_RPMEIU struct rpmInstallArguments_s * ia = &rpmIArgs; #endif -#if defined(IAM_RPMDB) - struct rpmDatabaseArguments_s * da = &rpmDBArgs; -#endif - -#if defined(IAM_RPMK) - QVA_t ka = &rpmQVKArgs; -#endif - -#if defined(IAM_RPMBT) || defined(IAM_RPMK) - char * passPhrase = ""; -#endif - - int arg; - - const char *optArg, *poptCtx; - pid_t pipeChild = 0; poptContext optCon; int ec = 0; - int status; - int p[2]; #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 */ - if (__progname == NULL) { - if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++; - else __progname = argv[0]; - } + optCon = rpmcliInit(argc, argv, optionsTable); /* Set the major mode based on argv[0] */ -#ifdef IAM_RPMBT - if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD; -#endif #ifdef IAM_RPMQV - if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY; - if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY; + if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY; + if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY; #endif #if defined(IAM_RPMQV) @@ -224,116 +101,14 @@ int main(int argc, char *argv[]) switch (bigMode) { case MODE_QUERY: qva->qva_mode = 'q'; break; case MODE_VERIFY: qva->qva_mode = 'V'; break; - case MODE_CHECKSIG: qva->qva_mode = 'K'; break; - case MODE_RESIGN: qva->qva_mode = 'R'; break; case MODE_INSTALL: case MODE_ERASE: - case MODE_BUILD: - case MODE_REBUILD: - case MODE_RECOMPILE: - case MODE_TARBUILD: - case MODE_INITDB: - case MODE_REBUILDDB: - case MODE_VERIFYDB: case MODE_UNKNOWN: default: break; } #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 */ -#ifdef IAM_RPMBT - poptCtx = "rpmbuild"; -#else - poptCtx = "rpm"; -#endif - - /* 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); - } -#if RPM_USES_POPTREADDEFAULTCONFIG - (void) poptReadDefaultConfig(optCon, 1); -#endif - 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_RPMBT - switch (ba->buildMode) { - case 'b': bigMode = MODE_BUILD; break; - case 't': bigMode = MODE_TARBUILD; break; - case 'B': bigMode = MODE_REBUILD; break; - case 'C': bigMode = MODE_RECOMPILE; break; - } - - if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN) - bigMode = MODE_BUILD; - - if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN) - bigMode = MODE_BUILD; - - if (ba->buildRootOverride && bigMode != MODE_BUILD && - bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) { - argerror("--buildroot may only be used during package builds"); - } -#endif /* IAM_RPMBT */ - -#ifdef IAM_RPMDB - if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) { - if (da->init) { - if (bigMode != MODE_UNKNOWN) - argerror(_("only one major mode may be specified")); - else - bigMode = MODE_INITDB; - } else - if (da->rebuild) { - if (bigMode != MODE_UNKNOWN) - argerror(_("only one major mode may be specified")); - else - bigMode = MODE_REBUILDDB; - } else - if (da->verify) { - if (bigMode != MODE_UNKNOWN) - argerror(_("only one major mode may be specified")); - else - bigMode = MODE_VERIFYDB; - } - } -#endif /* IAM_RPMDB */ - #ifdef IAM_RPMQV if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) { switch (qva->qva_mode) { @@ -342,7 +117,7 @@ int main(int argc, char *argv[]) } if (qva->qva_sourceCount) { - if (qva->qva_sourceCount > 2) + if (qva->qva_sourceCount > 1) argerror(_("one type of query/verify may be performed at a " "time")); } @@ -372,31 +147,10 @@ int main(int argc, char *argv[]) } #endif /* IAM_RPMEIU */ -#ifdef IAM_RPMK - if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) { - switch (ka->qva_mode) { - case RPMSIGN_NONE: - ka->sign = 0; - break; - case RPMSIGN_IMPORT_PUBKEY: - case RPMSIGN_CHK_SIGNATURE: - bigMode = MODE_CHECKSIG; - ka->sign = 0; - break; - case RPMSIGN_ADD_SIGNATURE: - case RPMSIGN_NEW_SIGNATURE: - case RPMSIGN_DEL_SIGNATURE: - bigMode = MODE_RESIGN; - ka->sign = (ka->qva_mode != RPMSIGN_DEL_SIGNATURE); - break; - } - } -#endif /* IAM_RPMK */ - #if defined(IAM_RPMEIU) if (!( bigMode == MODE_INSTALL ) && (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE))) - argerror(_("only installation, upgrading, rmsource and rmspec may be forced")); + argerror(_("only installation and upgrading may be forced")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE)) argerror(_("files may only be relocated during package installation")); @@ -412,13 +166,13 @@ int main(int argc, char *argv[]) if (ia->prefix && ia->prefix[0] != '/') argerror(_("arguments to --prefix must begin with a /")); - if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH)) + if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH)) argerror(_("--hash (-h) may only be specified during package " - "installation")); + "installation and erasure")); - if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT)) + if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT)) argerror(_("--percent may only be specified during package " - "installation")); + "installation and erasure")); if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG)) argerror(_("--replacepkgs may only be specified during package " @@ -449,7 +203,7 @@ int main(int argc, char *argv[]) argerror(_("--ignoresize may only be specified during package " "installation")); - if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE) + if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE) argerror(_("--allmatches may only be specified during package " "erasure")); @@ -462,258 +216,41 @@ int main(int argc, char *argv[]) argerror(_("--justdb may only be specified during package " "installation and erasure")); - if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && + if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY && (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers))) argerror(_("script disabling options may only be specified during " "package installation and erasure")); - if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && + if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY && (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers))) argerror(_("trigger disabling options may only be specified during " "package installation and erasure")); if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS)) argerror(_("--nodeps may only be specified during package " - "building, rebuilding, recompilation, installation," - "erasure, and verification")); + "installation, erasure, and verification")); if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST)) - argerror(_("--test may only be specified during package installation, " - "erasure, and building")); + argerror(_("--test may only be specified during package installation " + "and erasure")); #endif /* IAM_RPMEIU */ - if (rpmcliRootDir && rpmcliRootDir[1] && (bigMode & ~MODES_FOR_ROOT)) - argerror(_("--root (-r) may only be specified during " - "installation, erasure, querying, and " - "database rebuilds")); - - if (rpmcliRootDir) { - switch (urlIsURL(rpmcliRootDir)) { - default: - if (bigMode & MODES_FOR_ROOT) - break; - case URL_IS_UNKNOWN: - if (rpmcliRootDir[0] != '/') - argerror(_("arguments to --root (-r) must begin with a /")); - break; - } + if (rpmcliRootDir && rpmcliRootDir[0] != '/') { + argerror(_("arguments to --root (-r) must begin with a /")); } if (quiet) rpmSetVerbosity(RPMLOG_WARNING); -#if defined(IAM_RPMBT) || defined(IAM_RPMK) - if (0 -#if defined(IAM_RPMBT) - || ba->sign -#endif -#if defined(IAM_RPMK) - || ka->sign -#endif - ) - { - if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD || - bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) - { - const char ** av; - struct stat sb; - int errors = 0; - - if ((av = poptGetArgs(optCon)) == NULL) { - fprintf(stderr, _("no files to sign\n")); - errors++; - } else - while (*av) { - if (stat(*av, &sb)) { - fprintf(stderr, _("cannot access file %s\n"), *av); - errors++; - } - av++; - } - - if (errors) { - ec = errors; - goto exit; - } - - if (poptPeekArg(optCon)) { - int sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY); - switch (sigTag) { - case 0: - break; - case RPMSIGTAG_PGP: -#ifdef DYING /* XXX gpg can now be used for RSA signatures. */ - if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) && - !rpmDetectPGPVersion(NULL)) { - fprintf(stderr, _("pgp not found: ")); - ec = EXIT_FAILURE; - goto exit; - } -#endif - case RPMSIGTAG_GPG: - case RPMSIGTAG_DSA: - case RPMSIGTAG_RSA: - passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag); - if (passPhrase == NULL) { - fprintf(stderr, _("Pass phrase check failed\n")); - ec = EXIT_FAILURE; - goto exit; - } - fprintf(stderr, _("Pass phrase is good.\n")); - passPhrase = xstrdup(passPhrase); - break; - default: - fprintf(stderr, - _("Invalid %%_signature spec in macro file.\n")); - ec = EXIT_FAILURE; - goto exit; - break; - } - } - } else { - argerror(_("--sign may only be used during package building")); - } - } else { - /* Make rpmLookupSignatureType() return 0 ("none") from now on */ - (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE); - } -#endif /* IAM_RPMBT || IAM_RPMK */ - - if (rpmcliPipeOutput) { - if (pipe(p) < 0) { - fprintf(stderr, _("creating a pipe for --pipe failed: %m\n")); - goto exit; - } - - if (!(pipeChild = fork())) { - (void) signal(SIGPIPE, SIG_DFL); - (void) close(p[1]); - (void) dup2(p[0], STDIN_FILENO); - (void) close(p[0]); - (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL); - fprintf(stderr, _("exec failed\n")); - } - - (void) close(p[0]); - (void) dup2(p[1], STDOUT_FILENO); - (void) close(p[1]); - } + if (rpmcliPipeOutput && initPipe()) + exit(EXIT_FAILURE); ts = rpmtsCreate(); (void) rpmtsSetRootDir(ts, rpmcliRootDir); switch (bigMode) { -#ifdef IAM_RPMDB - case MODE_INITDB: - ec = rpmtsInitDB(ts, 0644); - break; - - case MODE_REBUILDDB: - { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}"); - rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags); - ec = rpmtsRebuildDB(ts); - vsflags = rpmtsSetVSFlags(ts, ovsflags); - } break; - case MODE_VERIFYDB: - ec = rpmtsVerifyDB(ts); - break; -#endif /* IAM_RPMDB */ - -#ifdef IAM_RPMBT - case MODE_REBUILD: - case MODE_RECOMPILE: - { const char * pkg; - - while (!rpmIsVerbose()) - rpmIncreaseVerbosity(); - - if (!poptPeekArg(optCon)) - argerror(_("no packages files given for rebuild")); - - ba->buildAmount = - RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK; - if (bigMode == MODE_REBUILD) { - ba->buildAmount |= RPMBUILD_PACKAGEBINARY; - ba->buildAmount |= RPMBUILD_RMSOURCE; - ba->buildAmount |= RPMBUILD_RMSPEC; - ba->buildAmount |= RPMBUILD_CLEAN; - ba->buildAmount |= RPMBUILD_RMBUILD; - } - - while ((pkg = poptGetArg(optCon))) { - char * specFile = NULL; - - ba->cookie = NULL; - ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie); - if (ec == 0) { - ba->rootdir = rpmcliRootDir; - ba->passPhrase = passPhrase; - ec = build(ts, specFile, ba, rpmcliRcfile); - } - ba->cookie = _free(ba->cookie); - specFile = _free(specFile); - - if (ec) - break; - } - - } break; - - case MODE_BUILD: - case MODE_TARBUILD: - { const char * pkg; - if (!quiet) while (!rpmIsVerbose()) - rpmIncreaseVerbosity(); - - switch (ba->buildChar) { - case 'a': - ba->buildAmount |= RPMBUILD_PACKAGESOURCE; - case 'b': - ba->buildAmount |= RPMBUILD_PACKAGEBINARY; - ba->buildAmount |= RPMBUILD_CLEAN; - case 'i': - ba->buildAmount |= RPMBUILD_INSTALL; - ba->buildAmount |= RPMBUILD_CHECK; - if ((ba->buildChar == 'i') && ba->shortCircuit) - break; - case 'c': - ba->buildAmount |= RPMBUILD_BUILD; - if ((ba->buildChar == 'c') && ba->shortCircuit) - break; - case 'p': - ba->buildAmount |= RPMBUILD_PREP; - break; - - case 'l': - ba->buildAmount |= RPMBUILD_FILECHECK; - break; - case 's': - ba->buildAmount |= RPMBUILD_PACKAGESOURCE; - break; - } - - if (!poptPeekArg(optCon)) { - if (bigMode == MODE_BUILD) - argerror(_("no spec files given for build")); - else - argerror(_("no tar files given for build")); - } - - while ((pkg = poptGetArg(optCon))) { - ba->rootdir = rpmcliRootDir; - ba->passPhrase = passPhrase; - ba->cookie = NULL; - ec = build(ts, pkg, ba, rpmcliRcfile); - if (ec) - break; - rpmFreeMacros(NULL); - (void) rpmReadConfigFiles(rpmcliRcfile, NULL); - } - } break; -#endif /* IAM_RPMBT */ - #ifdef IAM_RPMEIU case MODE_ERASE: - if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS; + if (ia->noDeps) ia->installInterfaceFlags |= UNINSTALL_NODEPS; if (!poptPeekArg(optCon)) { argerror(_("no packages given for erase")); @@ -761,13 +298,10 @@ int main(int argc, char *argv[]) #ifdef IAM_RPMQV case MODE_QUERY: - if (!poptPeekArg(optCon) - && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) + if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL)) argerror(_("no arguments given for query")); - qva->qva_specQuery = rpmspecQuery; ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); - qva->qva_specQuery = NULL; break; case MODE_VERIFY: @@ -776,48 +310,16 @@ int main(int argc, char *argv[]) verifyFlags &= ~qva->qva_flags; qva->qva_flags = (rpmQueryFlags) verifyFlags; - if (!poptPeekArg(optCon) - && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) + if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL)) argerror(_("no arguments given for verify")); ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); } break; #endif /* IAM_RPMQV */ -#ifdef IAM_RPMK - case MODE_CHECKSIG: - { rpmVerifyFlags verifyFlags = - (VERIFY_MD5|VERIFY_DIGEST|VERIFY_SIGNATURE); - - verifyFlags &= ~ka->qva_flags; - ka->qva_flags = (rpmQueryFlags) verifyFlags; - } - case MODE_RESIGN: - if (!poptPeekArg(optCon)) - argerror(_("no arguments given")); - ka->passPhrase = passPhrase; - ec = rpmcliSign(ts, ka, (ARGV_const_t) poptGetArgs(optCon)); - break; -#endif /* IAM_RPMK */ - #if !defined(IAM_RPMQV) case MODE_QUERY: case MODE_VERIFY: #endif -#if !defined(IAM_RPMK) - case MODE_CHECKSIG: - case MODE_RESIGN: -#endif -#if !defined(IAM_RPMDB) - case MODE_INITDB: - case MODE_REBUILDDB: - case MODE_VERIFYDB: -#endif -#if !defined(IAM_RPMBT) - case MODE_BUILD: - case MODE_REBUILD: - case MODE_RECOMPILE: - case MODE_TARBUILD: -#endif #if !defined(IAM_RPMEIU) case MODE_INSTALL: case MODE_ERASE: @@ -830,47 +332,23 @@ int main(int argc, char *argv[]) break; } -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 */ - rpmFreeFilesystems(); - rpmlogClose(); + rpmtsFree(ts); + if (finishPipe()) + ec = EXIT_FAILURE; #ifdef IAM_RPMQV - qva->qva_queryFormat = _free(qva->qva_queryFormat); -#endif - -#ifdef IAM_RPMBT - freeNames(); - ba->buildRootOverride = _free(ba->buildRootOverride); - ba->targets = _free(ba->targets); + free(qva->qva_queryFormat); #endif #ifdef IAM_RPMEIU - if (ia->relocations != NULL) - for (i = 0; i < ia->numRelocations; i++) - ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath); - ia->relocations = _free(ia->relocations); -#endif - -#if HAVE_MCHECK_H && HAVE_MTRACE - muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ + if (ia->relocations != NULL) { + for (i = 0; i < ia->numRelocations; i++) + free(ia->relocations[i].oldPath); + free(ia->relocations); + } #endif - /* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */ - if (ec > 254) ec = 254; + rpmcliFini(optCon); - return ec; + return RETVAL(ec); }