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