rpm
4.8.1
|
00001 #include "system.h" 00002 const char *__progname; 00003 00004 #define _AUTOHELP 00005 00006 #if defined(IAM_RPM) 00007 #define IAM_RPMBT 00008 #define IAM_RPMDB 00009 #define IAM_RPMEIU 00010 #define IAM_RPMQV 00011 #define IAM_RPMK 00012 #endif 00013 00014 #include <rpm/rpmcli.h> 00015 #include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */ 00016 #include <rpm/rpmbuild.h> 00017 #include <rpm/rpmlog.h> 00018 #include <rpm/rpmfileutil.h> 00019 00020 #include <rpm/rpmdb.h> 00021 #include <rpm/rpmps.h> 00022 #include <rpm/rpmts.h> 00023 00024 #ifdef IAM_RPMBT 00025 #include "build.h" 00026 #define GETOPT_REBUILD 1003 00027 #define GETOPT_RECOMPILE 1004 00028 #endif 00029 00030 #if defined(IAM_RPMBT) || defined(IAM_RPMK) 00031 #include "lib/signature.h" 00032 #endif 00033 00034 #include "debug.h" 00035 00036 enum modes { 00037 00038 MODE_QUERY = (1 << 0), 00039 MODE_VERIFY = (1 << 3), 00040 #define MODES_QV (MODE_QUERY | MODE_VERIFY) 00041 00042 MODE_INSTALL = (1 << 1), 00043 MODE_ERASE = (1 << 2), 00044 #define MODES_IE (MODE_INSTALL | MODE_ERASE) 00045 00046 MODE_BUILD = (1 << 4), 00047 MODE_REBUILD = (1 << 5), 00048 MODE_RECOMPILE = (1 << 8), 00049 MODE_TARBUILD = (1 << 11), 00050 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE) 00051 00052 MODE_CHECKSIG = (1 << 6), 00053 MODE_RESIGN = (1 << 7), 00054 #define MODES_K (MODE_CHECKSIG | MODE_RESIGN) 00055 00056 MODE_INITDB = (1 << 10), 00057 MODE_REBUILDDB = (1 << 12), 00058 MODE_VERIFYDB = (1 << 13), 00059 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB) 00060 00061 00062 MODE_UNKNOWN = 0 00063 }; 00064 00065 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB) 00066 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY) 00067 #define MODES_FOR_TEST (MODES_BT | MODES_IE) 00068 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB | MODES_K) 00069 00070 static int quiet; 00071 00072 /* the structure describing the options we take and the defaults */ 00073 static struct poptOption optionsTable[] = { 00074 00075 #ifdef IAM_RPMQV 00076 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0, 00077 N_("Query/Verify package selection options:"), 00078 NULL }, 00079 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0, 00080 N_("Query options (with -q or --query):"), 00081 NULL }, 00082 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0, 00083 N_("Verify options (with -V or --verify):"), 00084 NULL }, 00085 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliFtsPoptTable, 0, 00086 N_("File tree walk options (with --ftswalk):"), 00087 NULL }, 00088 #endif /* IAM_RPMQV */ 00089 00090 #ifdef IAM_RPMK 00091 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0, 00092 N_("Signature options:"), 00093 NULL }, 00094 #endif /* IAM_RPMK */ 00095 00096 #ifdef IAM_RPMDB 00097 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0, 00098 N_("Database options:"), 00099 NULL }, 00100 #endif /* IAM_RPMDB */ 00101 00102 #ifdef IAM_RPMBT 00103 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0, 00104 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"), 00105 NULL }, 00106 #endif /* IAM_RPMBT */ 00107 00108 #ifdef IAM_RPMEIU 00109 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0, 00110 N_("Install/Upgrade/Erase options:"), 00111 NULL }, 00112 #endif /* IAM_RPMEIU */ 00113 00114 { "quiet", '\0', 0, &quiet, 0, NULL, NULL}, 00115 00116 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0, 00117 N_("Common options for all rpm modes and executables:"), 00118 NULL }, 00119 00120 POPT_AUTOALIAS 00121 POPT_AUTOHELP 00122 POPT_TABLEEND 00123 }; 00124 00125 #ifdef __MINT__ 00126 /* MiNT cannot dynamically increase the stack. */ 00127 long _stksize = 64 * 1024L; 00128 #endif 00129 00130 RPM_GNUC_NORETURN 00131 static void argerror(const char * desc) 00132 { 00133 fprintf(stderr, _("%s: %s\n"), __progname, desc); 00134 exit(EXIT_FAILURE); 00135 } 00136 00137 static void printVersion(FILE * fp) 00138 { 00139 fprintf(fp, _("RPM version %s\n"), rpmEVR); 00140 } 00141 00142 static void printBanner(FILE * fp) 00143 { 00144 fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n")); 00145 fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n")); 00146 } 00147 00148 static void printUsage(poptContext con, FILE * fp, int flags) 00149 { 00150 printVersion(fp); 00151 printBanner(fp); 00152 fprintf(fp, "\n"); 00153 00154 if (rpmIsVerbose()) 00155 poptPrintHelp(con, fp, flags); 00156 else 00157 poptPrintUsage(con, fp, flags); 00158 } 00159 00160 int main(int argc, char *argv[]) 00161 { 00162 rpmts ts = NULL; 00163 enum modes bigMode = MODE_UNKNOWN; 00164 00165 #if defined(IAM_RPMQV) 00166 QVA_t qva = &rpmQVKArgs; 00167 #endif 00168 00169 #ifdef IAM_RPMBT 00170 BTA_t ba = &rpmBTArgs; 00171 #endif 00172 00173 #ifdef IAM_RPMEIU 00174 struct rpmInstallArguments_s * ia = &rpmIArgs; 00175 #endif 00176 00177 #if defined(IAM_RPMDB) 00178 struct rpmDatabaseArguments_s * da = &rpmDBArgs; 00179 #endif 00180 00181 #if defined(IAM_RPMK) 00182 QVA_t ka = &rpmQVKArgs; 00183 #endif 00184 00185 #if defined(IAM_RPMBT) || defined(IAM_RPMK) 00186 char * passPhrase = ""; 00187 #endif 00188 00189 int arg; 00190 00191 const char *optArg, *poptCtx; 00192 pid_t pipeChild = 0; 00193 poptContext optCon; 00194 int ec = 0; 00195 int status; 00196 int p[2]; 00197 #ifdef IAM_RPMEIU 00198 int i; 00199 #endif 00200 00201 #if HAVE_MCHECK_H && HAVE_MTRACE 00202 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ 00203 #endif 00204 setprogname(argv[0]); /* Retrofit glibc __progname */ 00205 00206 /* XXX glibc churn sanity */ 00207 if (__progname == NULL) { 00208 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++; 00209 else __progname = argv[0]; 00210 } 00211 00212 /* Set the major mode based on argv[0] */ 00213 #ifdef IAM_RPMBT 00214 if (rstreq(__progname, "rpmbuild")) bigMode = MODE_BUILD; 00215 #endif 00216 #ifdef IAM_RPMQV 00217 if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY; 00218 if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY; 00219 #endif 00220 00221 #if defined(IAM_RPMQV) 00222 /* Jumpstart option from argv[0] if necessary. */ 00223 switch (bigMode) { 00224 case MODE_QUERY: qva->qva_mode = 'q'; break; 00225 case MODE_VERIFY: qva->qva_mode = 'V'; break; 00226 case MODE_CHECKSIG: qva->qva_mode = 'K'; break; 00227 case MODE_RESIGN: qva->qva_mode = 'R'; break; 00228 case MODE_INSTALL: 00229 case MODE_ERASE: 00230 case MODE_BUILD: 00231 case MODE_REBUILD: 00232 case MODE_RECOMPILE: 00233 case MODE_TARBUILD: 00234 case MODE_INITDB: 00235 case MODE_REBUILDDB: 00236 case MODE_VERIFYDB: 00237 case MODE_UNKNOWN: 00238 default: 00239 break; 00240 } 00241 #endif 00242 00243 #if defined(ENABLE_NLS) 00244 /* set up the correct locale */ 00245 (void) setlocale(LC_ALL, "" ); 00246 00247 bindtextdomain(PACKAGE, LOCALEDIR); 00248 textdomain(PACKAGE); 00249 #endif 00250 00251 rpmSetVerbosity(RPMLOG_NOTICE); /* XXX silly use by showrc */ 00252 00253 /* Only build has it's own set of aliases, everything else uses rpm */ 00254 #ifdef IAM_RPMBT 00255 poptCtx = "rpmbuild"; 00256 #else 00257 poptCtx = "rpm"; 00258 #endif 00259 00260 /* Make a first pass through the arguments, looking for --rcfile */ 00261 /* We need to handle that before dealing with the rest of the arguments. */ 00262 /* XXX popt argv definition should be fixed instead of casting... */ 00263 optCon = poptGetContext(poptCtx, argc, (const char **)argv, optionsTable, 0); 00264 { 00265 char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL); 00266 (void) poptReadConfigFile(optCon, poptfile); 00267 free(poptfile); 00268 } 00269 (void) poptReadDefaultConfig(optCon, 1); 00270 poptSetExecPath(optCon, rpmConfigDir(), 1); 00271 00272 while ((arg = poptGetNextOpt(optCon)) > 0) { 00273 optArg = poptGetOptArg(optCon); 00274 00275 switch (arg) { 00276 default: 00277 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg); 00278 exit(EXIT_FAILURE); 00279 } 00280 } 00281 00282 if (arg < -1) { 00283 fprintf(stderr, "%s: %s\n", 00284 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 00285 poptStrerror(arg)); 00286 exit(EXIT_FAILURE); 00287 } 00288 00289 rpmcliConfigured(); 00290 00291 #ifdef IAM_RPMBT 00292 switch (ba->buildMode) { 00293 case 'b': bigMode = MODE_BUILD; break; 00294 case 't': bigMode = MODE_TARBUILD; break; 00295 case 'B': bigMode = MODE_REBUILD; break; 00296 case 'C': bigMode = MODE_RECOMPILE; break; 00297 } 00298 00299 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN) 00300 bigMode = MODE_BUILD; 00301 00302 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN) 00303 bigMode = MODE_BUILD; 00304 00305 if (ba->buildRootOverride && bigMode != MODE_BUILD && 00306 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) { 00307 argerror("--buildroot may only be used during package builds"); 00308 } 00309 #endif /* IAM_RPMBT */ 00310 00311 #ifdef IAM_RPMDB 00312 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) { 00313 if (da->init) { 00314 if (bigMode != MODE_UNKNOWN) 00315 argerror(_("only one major mode may be specified")); 00316 else 00317 bigMode = MODE_INITDB; 00318 } else 00319 if (da->rebuild) { 00320 if (bigMode != MODE_UNKNOWN) 00321 argerror(_("only one major mode may be specified")); 00322 else 00323 bigMode = MODE_REBUILDDB; 00324 } else 00325 if (da->verify) { 00326 if (bigMode != MODE_UNKNOWN) 00327 argerror(_("only one major mode may be specified")); 00328 else 00329 bigMode = MODE_VERIFYDB; 00330 } 00331 } 00332 #endif /* IAM_RPMDB */ 00333 00334 #ifdef IAM_RPMQV 00335 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) { 00336 switch (qva->qva_mode) { 00337 case 'q': bigMode = MODE_QUERY; break; 00338 case 'V': bigMode = MODE_VERIFY; break; 00339 } 00340 00341 if (qva->qva_sourceCount) { 00342 if (qva->qva_sourceCount > 2) 00343 argerror(_("one type of query/verify may be performed at a " 00344 "time")); 00345 } 00346 if (qva->qva_flags && (bigMode & ~MODES_QV)) 00347 argerror(_("unexpected query flags")); 00348 00349 if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) 00350 argerror(_("unexpected query format")); 00351 00352 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) 00353 argerror(_("unexpected query source")); 00354 } 00355 #endif /* IAM_RPMQV */ 00356 00357 #ifdef IAM_RPMEIU 00358 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE)) 00359 { int iflags = (ia->installInterfaceFlags & 00360 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)); 00361 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE); 00362 00363 if (iflags & eflags) 00364 argerror(_("only one major mode may be specified")); 00365 else if (iflags) 00366 bigMode = MODE_INSTALL; 00367 else if (eflags) 00368 bigMode = MODE_ERASE; 00369 } 00370 #endif /* IAM_RPMEIU */ 00371 00372 #ifdef IAM_RPMK 00373 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) { 00374 switch (ka->qva_mode) { 00375 case RPMSIGN_NONE: 00376 ka->sign = 0; 00377 break; 00378 case RPMSIGN_IMPORT_PUBKEY: 00379 case RPMSIGN_CHK_SIGNATURE: 00380 bigMode = MODE_CHECKSIG; 00381 ka->sign = 0; 00382 break; 00383 case RPMSIGN_ADD_SIGNATURE: 00384 case RPMSIGN_NEW_SIGNATURE: 00385 case RPMSIGN_DEL_SIGNATURE: 00386 bigMode = MODE_RESIGN; 00387 ka->sign = (ka->qva_mode != RPMSIGN_DEL_SIGNATURE); 00388 break; 00389 } 00390 } 00391 #endif /* IAM_RPMK */ 00392 00393 #if defined(IAM_RPMEIU) 00394 if (!( bigMode == MODE_INSTALL ) && 00395 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE))) 00396 argerror(_("only installation, upgrading, rmsource and rmspec may be forced")); 00397 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE)) 00398 argerror(_("files may only be relocated during package installation")); 00399 00400 if (ia->relocations && ia->prefix) 00401 argerror(_("cannot use --prefix with --relocate or --excludepath")); 00402 00403 if (bigMode != MODE_INSTALL && ia->relocations) 00404 argerror(_("--relocate and --excludepath may only be used when installing new packages")); 00405 00406 if (bigMode != MODE_INSTALL && ia->prefix) 00407 argerror(_("--prefix may only be used when installing new packages")); 00408 00409 if (ia->prefix && ia->prefix[0] != '/') 00410 argerror(_("arguments to --prefix must begin with a /")); 00411 00412 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH)) 00413 argerror(_("--hash (-h) may only be specified during package " 00414 "installation")); 00415 00416 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT)) 00417 argerror(_("--percent may only be specified during package " 00418 "installation")); 00419 00420 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG)) 00421 argerror(_("--replacepkgs may only be specified during package " 00422 "installation")); 00423 00424 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) 00425 argerror(_("--excludedocs may only be specified during package " 00426 "installation")); 00427 00428 if (bigMode != MODE_INSTALL && ia->incldocs) 00429 argerror(_("--includedocs may only be specified during package " 00430 "installation")); 00431 00432 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS)) 00433 argerror(_("only one of --excludedocs and --includedocs may be " 00434 "specified")); 00435 00436 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH)) 00437 argerror(_("--ignorearch may only be specified during package " 00438 "installation")); 00439 00440 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS)) 00441 argerror(_("--ignoreos may only be specified during package " 00442 "installation")); 00443 00444 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && 00445 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES))) 00446 argerror(_("--ignoresize may only be specified during package " 00447 "installation")); 00448 00449 if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE) 00450 argerror(_("--allmatches may only be specified during package " 00451 "erasure")); 00452 00453 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL) 00454 argerror(_("--allfiles may only be specified during package " 00455 "installation")); 00456 00457 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) && 00458 bigMode != MODE_INSTALL && bigMode != MODE_ERASE) 00459 argerror(_("--justdb may only be specified during package " 00460 "installation and erasure")); 00461 00462 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY && 00463 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers))) 00464 argerror(_("script disabling options may only be specified during " 00465 "package installation and erasure")); 00466 00467 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY && 00468 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers))) 00469 argerror(_("trigger disabling options may only be specified during " 00470 "package installation and erasure")); 00471 00472 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS)) 00473 argerror(_("--nodeps may only be specified during package " 00474 "building, rebuilding, recompilation, installation," 00475 "erasure, and verification")); 00476 00477 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST)) 00478 argerror(_("--test may only be specified during package installation, " 00479 "erasure, and building")); 00480 #endif /* IAM_RPMEIU */ 00481 00482 if (rpmcliRootDir && rpmcliRootDir[1] && (bigMode & ~MODES_FOR_ROOT)) 00483 argerror(_("--root (-r) may only be specified during " 00484 "installation, erasure, querying, and " 00485 "database rebuilds")); 00486 00487 if (rpmcliRootDir) { 00488 switch (urlIsURL(rpmcliRootDir)) { 00489 default: 00490 if (bigMode & MODES_FOR_ROOT) 00491 break; 00492 case URL_IS_UNKNOWN: 00493 if (rpmcliRootDir[0] != '/') 00494 argerror(_("arguments to --root (-r) must begin with a /")); 00495 break; 00496 } 00497 } 00498 00499 if (quiet) 00500 rpmSetVerbosity(RPMLOG_WARNING); 00501 00502 #if defined(IAM_RPMBT) || defined(IAM_RPMK) 00503 if (0 00504 #if defined(IAM_RPMBT) 00505 || ba->sign 00506 #endif 00507 #if defined(IAM_RPMK) 00508 || ka->sign 00509 #endif 00510 ) 00511 { 00512 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD || 00513 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) 00514 { 00515 const char ** av; 00516 struct stat sb; 00517 int errors = 0; 00518 00519 if ((av = poptGetArgs(optCon)) == NULL) { 00520 fprintf(stderr, _("no files to sign\n")); 00521 errors++; 00522 } else 00523 while (*av) { 00524 if (stat(*av, &sb)) { 00525 fprintf(stderr, _("cannot access file %s\n"), *av); 00526 errors++; 00527 } 00528 av++; 00529 } 00530 00531 if (errors) { 00532 ec = errors; 00533 goto exit; 00534 } 00535 00536 if (poptPeekArg(optCon)) { 00537 int sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY); 00538 switch (sigTag) { 00539 case 0: 00540 break; 00541 case RPMSIGTAG_PGP: 00542 case RPMSIGTAG_GPG: 00543 case RPMSIGTAG_DSA: 00544 case RPMSIGTAG_RSA: 00545 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag); 00546 if (passPhrase == NULL) { 00547 fprintf(stderr, _("Pass phrase check failed\n")); 00548 ec = EXIT_FAILURE; 00549 goto exit; 00550 } 00551 fprintf(stderr, _("Pass phrase is good.\n")); 00552 passPhrase = xstrdup(passPhrase); 00553 break; 00554 default: 00555 fprintf(stderr, 00556 _("Invalid %%_signature spec in macro file.\n")); 00557 ec = EXIT_FAILURE; 00558 goto exit; 00559 break; 00560 } 00561 } 00562 } else { 00563 argerror(_("--sign may only be used during package building")); 00564 } 00565 } else { 00566 /* Make rpmLookupSignatureType() return 0 ("none") from now on */ 00567 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE); 00568 } 00569 #endif /* IAM_RPMBT || IAM_RPMK */ 00570 00571 if (rpmcliPipeOutput) { 00572 if (pipe(p) < 0) { 00573 fprintf(stderr, _("creating a pipe for --pipe failed: %m\n")); 00574 goto exit; 00575 } 00576 00577 if (!(pipeChild = fork())) { 00578 (void) signal(SIGPIPE, SIG_DFL); 00579 (void) close(p[1]); 00580 (void) dup2(p[0], STDIN_FILENO); 00581 (void) close(p[0]); 00582 (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL); 00583 fprintf(stderr, _("exec failed\n")); 00584 } 00585 00586 (void) close(p[0]); 00587 (void) dup2(p[1], STDOUT_FILENO); 00588 (void) close(p[1]); 00589 } 00590 00591 ts = rpmtsCreate(); 00592 (void) rpmtsSetRootDir(ts, rpmcliRootDir); 00593 switch (bigMode) { 00594 #ifdef IAM_RPMDB 00595 case MODE_INITDB: 00596 ec = rpmtsInitDB(ts, 0644); 00597 break; 00598 00599 case MODE_REBUILDDB: 00600 { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}"); 00601 rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags); 00602 ec = rpmtsRebuildDB(ts); 00603 vsflags = rpmtsSetVSFlags(ts, ovsflags); 00604 } break; 00605 case MODE_VERIFYDB: 00606 ec = rpmtsVerifyDB(ts); 00607 break; 00608 #endif /* IAM_RPMDB */ 00609 00610 #ifdef IAM_RPMBT 00611 case MODE_REBUILD: 00612 case MODE_RECOMPILE: 00613 { const char * pkg; 00614 00615 while (!rpmIsVerbose()) 00616 rpmIncreaseVerbosity(); 00617 00618 if (!poptPeekArg(optCon)) 00619 argerror(_("no packages files given for rebuild")); 00620 00621 ba->buildAmount = 00622 RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK; 00623 if (bigMode == MODE_REBUILD) { 00624 ba->buildAmount |= RPMBUILD_PACKAGEBINARY; 00625 ba->buildAmount |= RPMBUILD_RMSOURCE; 00626 ba->buildAmount |= RPMBUILD_RMSPEC; 00627 ba->buildAmount |= RPMBUILD_CLEAN; 00628 ba->buildAmount |= RPMBUILD_RMBUILD; 00629 } 00630 00631 while ((pkg = poptGetArg(optCon))) { 00632 char * specFile = NULL; 00633 00634 ba->cookie = NULL; 00635 ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie); 00636 if (ec == 0) { 00637 ba->rootdir = rpmcliRootDir; 00638 ba->passPhrase = passPhrase; 00639 ec = build(ts, specFile, ba, rpmcliRcfile); 00640 } 00641 ba->cookie = _free(ba->cookie); 00642 specFile = _free(specFile); 00643 00644 if (ec) 00645 break; 00646 } 00647 00648 } break; 00649 00650 case MODE_BUILD: 00651 case MODE_TARBUILD: 00652 { const char * pkg; 00653 if (!quiet) while (!rpmIsVerbose()) 00654 rpmIncreaseVerbosity(); 00655 00656 switch (ba->buildChar) { 00657 case 'a': 00658 ba->buildAmount |= RPMBUILD_PACKAGESOURCE; 00659 case 'b': 00660 ba->buildAmount |= RPMBUILD_PACKAGEBINARY; 00661 ba->buildAmount |= RPMBUILD_CLEAN; 00662 case 'i': 00663 ba->buildAmount |= RPMBUILD_INSTALL; 00664 ba->buildAmount |= RPMBUILD_CHECK; 00665 if (ba->shortCircuit) 00666 break; 00667 case 'c': 00668 ba->buildAmount |= RPMBUILD_BUILD; 00669 if (ba->shortCircuit) 00670 break; 00671 case 'p': 00672 ba->buildAmount |= RPMBUILD_PREP; 00673 break; 00674 00675 case 'l': 00676 ba->buildAmount |= RPMBUILD_FILECHECK; 00677 break; 00678 case 's': 00679 ba->buildAmount |= RPMBUILD_PACKAGESOURCE; 00680 break; 00681 } 00682 00683 if (!poptPeekArg(optCon)) { 00684 if (bigMode == MODE_BUILD) 00685 argerror(_("no spec files given for build")); 00686 else 00687 argerror(_("no tar files given for build")); 00688 } 00689 00690 while ((pkg = poptGetArg(optCon))) { 00691 ba->rootdir = rpmcliRootDir; 00692 ba->passPhrase = passPhrase; 00693 ba->cookie = NULL; 00694 ec = build(ts, pkg, ba, rpmcliRcfile); 00695 if (ec) 00696 break; 00697 rpmFreeMacros(NULL); 00698 (void) rpmReadConfigFiles(rpmcliRcfile, NULL); 00699 } 00700 } break; 00701 #endif /* IAM_RPMBT */ 00702 00703 #ifdef IAM_RPMEIU 00704 case MODE_ERASE: 00705 if (ia->noDeps) ia->installInterfaceFlags |= UNINSTALL_NODEPS; 00706 00707 if (!poptPeekArg(optCon)) { 00708 argerror(_("no packages given for erase")); 00709 } else { 00710 ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon)); 00711 } 00712 break; 00713 00714 case MODE_INSTALL: 00715 00716 /* RPMTRANS_FLAG_KEEPOBSOLETE */ 00717 00718 if (!ia->incldocs) { 00719 if (ia->transFlags & RPMTRANS_FLAG_NODOCS) { 00720 ; 00721 } else if (rpmExpandNumeric("%{_excludedocs}")) 00722 ia->transFlags |= RPMTRANS_FLAG_NODOCS; 00723 } 00724 00725 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS; 00726 00727 /* we've already ensured !(!ia->prefix && !ia->relocations) */ 00728 if (ia->prefix) { 00729 ia->relocations = xmalloc(2 * sizeof(*ia->relocations)); 00730 ia->relocations[0].oldPath = NULL; /* special case magic */ 00731 ia->relocations[0].newPath = ia->prefix; 00732 ia->relocations[1].oldPath = NULL; 00733 ia->relocations[1].newPath = NULL; 00734 } else if (ia->relocations) { 00735 ia->relocations = xrealloc(ia->relocations, 00736 sizeof(*ia->relocations) * (ia->numRelocations + 1)); 00737 ia->relocations[ia->numRelocations].oldPath = NULL; 00738 ia->relocations[ia->numRelocations].newPath = NULL; 00739 } 00740 00741 if (!poptPeekArg(optCon)) { 00742 argerror(_("no packages given for install")); 00743 } else { 00744 /* FIX: ia->relocations[0].newPath undefined */ 00745 ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon)); 00746 } 00747 break; 00748 00749 #endif /* IAM_RPMEIU */ 00750 00751 #ifdef IAM_RPMQV 00752 case MODE_QUERY: 00753 if (!poptPeekArg(optCon) 00754 && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) 00755 argerror(_("no arguments given for query")); 00756 00757 qva->qva_specQuery = rpmspecQuery; 00758 ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); 00759 qva->qva_specQuery = NULL; 00760 break; 00761 00762 case MODE_VERIFY: 00763 { rpmVerifyFlags verifyFlags = VERIFY_ALL; 00764 00765 verifyFlags &= ~qva->qva_flags; 00766 qva->qva_flags = (rpmQueryFlags) verifyFlags; 00767 00768 if (!poptPeekArg(optCon) 00769 && !(qva->qva_source == RPMQV_ALL || qva->qva_source == RPMQV_HDLIST)) 00770 argerror(_("no arguments given for verify")); 00771 ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon)); 00772 } break; 00773 #endif /* IAM_RPMQV */ 00774 00775 #ifdef IAM_RPMK 00776 case MODE_CHECKSIG: 00777 { rpmVerifyFlags verifyFlags = 00778 (VERIFY_FILEDIGEST|VERIFY_DIGEST|VERIFY_SIGNATURE); 00779 00780 verifyFlags &= ~ka->qva_flags; 00781 ka->qva_flags = (rpmQueryFlags) verifyFlags; 00782 } 00783 case MODE_RESIGN: 00784 if (!poptPeekArg(optCon)) 00785 argerror(_("no arguments given")); 00786 ka->passPhrase = passPhrase; 00787 ec = rpmcliSign(ts, ka, (ARGV_const_t) poptGetArgs(optCon)); 00788 break; 00789 #endif /* IAM_RPMK */ 00790 00791 #if !defined(IAM_RPMQV) 00792 case MODE_QUERY: 00793 case MODE_VERIFY: 00794 #endif 00795 #if !defined(IAM_RPMK) 00796 case MODE_CHECKSIG: 00797 case MODE_RESIGN: 00798 #endif 00799 #if !defined(IAM_RPMDB) 00800 case MODE_INITDB: 00801 case MODE_REBUILDDB: 00802 case MODE_VERIFYDB: 00803 #endif 00804 #if !defined(IAM_RPMBT) 00805 case MODE_BUILD: 00806 case MODE_REBUILD: 00807 case MODE_RECOMPILE: 00808 case MODE_TARBUILD: 00809 #endif 00810 #if !defined(IAM_RPMEIU) 00811 case MODE_INSTALL: 00812 case MODE_ERASE: 00813 #endif 00814 case MODE_UNKNOWN: 00815 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) { 00816 printUsage(optCon, stderr, 0); 00817 ec = argc; 00818 } 00819 break; 00820 } 00821 00822 exit: 00823 00824 ts = rpmtsFree(ts); 00825 00826 optCon = poptFreeContext(optCon); 00827 rpmFreeMacros(NULL); 00828 rpmFreeMacros(rpmCLIMacroContext); 00829 rpmFreeRpmrc(); 00830 00831 if (pipeChild) { 00832 (void) fclose(stdout); 00833 (void) waitpid(pipeChild, &status, 0); 00834 } 00835 00836 /* keeps memory leak checkers quiet */ 00837 rpmFreeFilesystems(); 00838 rpmlogClose(); 00839 00840 #ifdef IAM_RPMQV 00841 qva->qva_queryFormat = _free(qva->qva_queryFormat); 00842 #endif 00843 00844 #ifdef IAM_RPMBT 00845 freeNames(); 00846 ba->buildRootOverride = _free(ba->buildRootOverride); 00847 ba->targets = _free(ba->targets); 00848 #endif 00849 00850 #ifdef IAM_RPMEIU 00851 if (ia->relocations != NULL) 00852 for (i = 0; i < ia->numRelocations; i++) 00853 ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath); 00854 ia->relocations = _free(ia->relocations); 00855 #endif 00856 00857 #if HAVE_MCHECK_H && HAVE_MTRACE 00858 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ 00859 #endif 00860 00861 /* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */ 00862 if (ec > 254) ec = 254; 00863 00864 return ec; 00865 }