Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

lib/psm.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include <rpmio_internal.h>
00009 #include <rpmlib.h>
00010 #include <rpmmacro.h>
00011 #include <rpmurl.h>
00012 
00013 #include "cpio.h"
00014 #include "fsm.h"                /* XXX CPIO_FOO/FSM_FOO constants */
00015 #include "psm.h"
00016 
00017 #include "rpmds.h"
00018 
00019 #define _RPMFI_INTERNAL
00020 #include "rpmfi.h"
00021 
00022 #define _RPMTE_INTERNAL
00023 #include "rpmte.h"
00024 
00025 #define _RPMTS_INTERNAL         /* XXX ts->notify */
00026 #include "rpmts.h"
00027 
00028 #include "rpmlead.h"            /* writeLead proto */
00029 #include "signature.h"          /* signature constants */
00030 #include "legacy.h"             /* XXX rpmfiBuildFNames() */
00031 #include "misc.h"               /* XXX stripTrailingChar() */
00032 #include "rpmdb.h"              /* XXX for db_chrootDone */
00033 #include "debug.h"
00034 
00035 #define _PSM_DEBUG      0
00036 /*@unchecked@*/
00037 int _psm_debug = _PSM_DEBUG;
00038 /*@unchecked@*/
00039 int _psm_threads = 0;
00040 
00041 /*@access FD_t @*/              /* XXX void ptr args */
00042 /*@access rpmpsm @*/
00043 
00044 /*@access rpmfi @*/
00045 /*@access rpmte @*/     /* XXX rpmInstallSourcePackage */
00046 /*@access rpmts @*/     /* XXX ts->notify */
00047 
00048 int rpmVersionCompare(Header first, Header second)
00049 {
00050     const char * one, * two;
00051     int_32 * epochOne, * epochTwo;
00052     int rc;
00053 
00054     if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
00055         epochOne = NULL;
00056     if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo, NULL))
00057         epochTwo = NULL;
00058 
00059     if (epochOne != NULL && epochTwo == NULL)
00060         return 1;
00061     else if (epochOne == NULL && epochTwo != NULL)
00062         return -1;
00063     else if (epochOne != NULL && epochTwo != NULL) {
00064 /*@-boundsread@*/
00065         if (*epochOne < *epochTwo)
00066             return -1;
00067         else if (*epochOne > *epochTwo)
00068             return 1;
00069 /*@=boundsread@*/
00070     }
00071 
00072     rc = headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
00073     rc = headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
00074 
00075     rc = rpmvercmp(one, two);
00076     if (rc)
00077         return rc;
00078 
00079     rc = headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
00080     rc = headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
00081 
00082     return rpmvercmp(one, two);
00083 }
00084 
00089 /*@observer@*/ /*@unchecked@*/
00090 static struct tagMacro {
00091 /*@observer@*/ /*@null@*/ const char *  macroname; 
00092     rpmTag      tag;            
00093 } tagMacros[] = {
00094     { "name",           RPMTAG_NAME },
00095     { "version",        RPMTAG_VERSION },
00096     { "release",        RPMTAG_RELEASE },
00097     { "epoch",          RPMTAG_EPOCH },
00098     { NULL, 0 }
00099 };
00100 
00107 static int rpmInstallLoadMacros(rpmfi fi, Header h)
00108         /*@globals rpmGlobalMacroContext @*/
00109         /*@modifies rpmGlobalMacroContext @*/
00110 {
00111     HGE_t hge = (HGE_t) fi->hge;
00112     struct tagMacro * tagm;
00113     union {
00114 /*@unused@*/ void * ptr;
00115 /*@unused@*/ const char ** argv;
00116         const char * str;
00117         int_32 * i32p;
00118     } body;
00119     char numbuf[32];
00120     rpmTagType type;
00121 
00122     for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
00123         if (!hge(h, tagm->tag, &type, (void **) &body, NULL))
00124             continue;
00125         switch (type) {
00126         case RPM_INT32_TYPE:
00127 /*@-boundsread@*/
00128             sprintf(numbuf, "%d", *body.i32p);
00129 /*@=boundsread@*/
00130             addMacro(NULL, tagm->macroname, NULL, numbuf, -1);
00131             /*@switchbreak@*/ break;
00132         case RPM_STRING_TYPE:
00133             addMacro(NULL, tagm->macroname, NULL, body.str, -1);
00134             /*@switchbreak@*/ break;
00135         case RPM_NULL_TYPE:
00136         case RPM_CHAR_TYPE:
00137         case RPM_INT8_TYPE:
00138         case RPM_INT16_TYPE:
00139         case RPM_BIN_TYPE:
00140         case RPM_STRING_ARRAY_TYPE:
00141         case RPM_I18NSTRING_TYPE:
00142         default:
00143             /*@switchbreak@*/ break;
00144         }
00145     }
00146     return 0;
00147 }
00148 
00154 /*@-bounds@*/
00155 static rpmRC markReplacedFiles(const rpmpsm psm)
00156         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00157         /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
00158 {
00159     const rpmts ts = psm->ts;
00160     rpmfi fi = psm->fi;
00161     HGE_t hge = (HGE_t)fi->hge;
00162     sharedFileInfo replaced = fi->replaced;
00163     sharedFileInfo sfi;
00164     rpmdbMatchIterator mi;
00165     Header h;
00166     unsigned int * offsets;
00167     unsigned int prev;
00168     int num, xx;
00169 
00170     if (!(rpmfiFC(fi) > 0 && fi->replaced))
00171         return RPMRC_OK;
00172 
00173     num = prev = 0;
00174     for (sfi = replaced; sfi->otherPkg; sfi++) {
00175         if (prev && prev == sfi->otherPkg)
00176             continue;
00177         prev = sfi->otherPkg;
00178         num++;
00179     }
00180     if (num == 0)
00181         return RPMRC_OK;
00182 
00183     offsets = alloca(num * sizeof(*offsets));
00184     offsets[0] = 0;
00185     num = prev = 0;
00186     for (sfi = replaced; sfi->otherPkg; sfi++) {
00187         if (prev && prev == sfi->otherPkg)
00188             continue;
00189         prev = sfi->otherPkg;
00190         offsets[num++] = sfi->otherPkg;
00191     }
00192 
00193     mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
00194     xx = rpmdbAppendIterator(mi, offsets, num);
00195     xx = rpmdbSetIteratorRewrite(mi, 1);
00196 
00197     sfi = replaced;
00198     while ((h = rpmdbNextIterator(mi)) != NULL) {
00199         char * secStates;
00200         int modified;
00201         int count;
00202 
00203         modified = 0;
00204 
00205         if (!hge(h, RPMTAG_FILESTATES, NULL, (void **)&secStates, &count))
00206             continue;
00207         
00208         prev = rpmdbGetIteratorOffset(mi);
00209         num = 0;
00210         while (sfi->otherPkg && sfi->otherPkg == prev) {
00211             assert(sfi->otherFileNum < count);
00212             if (secStates[sfi->otherFileNum] != RPMFILE_STATE_REPLACED) {
00213                 secStates[sfi->otherFileNum] = RPMFILE_STATE_REPLACED;
00214                 if (modified == 0) {
00215                     /* Modified header will be rewritten. */
00216                     modified = 1;
00217                     xx = rpmdbSetIteratorModified(mi, modified);
00218                 }
00219                 num++;
00220             }
00221             sfi++;
00222         }
00223     }
00224     mi = rpmdbFreeIterator(mi);
00225 
00226     return RPMRC_OK;
00227 }
00228 /*@=bounds@*/
00229 
00230 rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd,
00231                 const char ** specFilePtr, const char ** cookie)
00232 {
00233     int scareMem = 1;
00234     rpmfi fi = NULL;
00235     const char * _sourcedir = NULL;
00236     const char * _specdir = NULL;
00237     const char * specFile = NULL;
00238     HGE_t hge;
00239     HFD_t hfd;
00240     Header h = NULL;
00241     struct rpmpsm_s psmbuf;
00242     rpmpsm psm = &psmbuf;
00243     int isSource;
00244     rpmRC rpmrc;
00245     int i;
00246 
00247     memset(psm, 0, sizeof(*psm));
00248     psm->ts = rpmtsLink(ts, "InstallSourcePackage");
00249 
00250     rpmrc = rpmReadPackageFile(ts, fd, "InstallSourcePackage", &h);
00251     switch (rpmrc) {
00252     case RPMRC_NOTTRUSTED:
00253     case RPMRC_NOKEY:
00254     case RPMRC_OK:
00255         break;
00256     default:
00257         goto exit;
00258         /*@notreached@*/ break;
00259     }
00260     if (h == NULL)
00261         goto exit;
00262 
00263     rpmrc = RPMRC_OK;
00264 
00265     isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
00266 
00267     if (!isSource) {
00268         rpmError(RPMERR_NOTSRPM, _("source package expected, binary found\n"));
00269         rpmrc = RPMRC_FAIL;
00270         goto exit;
00271     }
00272 
00273     (void) rpmtsAddInstallElement(ts, h, NULL, 0, NULL);
00274 
00275     fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
00276     h = headerFree(h);
00277 
00278     if (fi == NULL) {   /* XXX can't happen */
00279         rpmrc = RPMRC_FAIL;
00280         goto exit;
00281     }
00282 
00283 /*@-onlytrans@*/        /* FIX: te reference */
00284     fi->te = rpmtsElement(ts, 0);
00285 /*@=onlytrans@*/
00286     if (fi->te == NULL) {       /* XXX can't happen */
00287         rpmrc = RPMRC_FAIL;
00288         goto exit;
00289     }
00290 
00291 /*@-nullpass@*/         /* FIX fi->h may be null */
00292     fi->te->h = headerLink(fi->h);
00293 /*@=nullpass@*/
00294     fi->te->fd = fdLink(fd, "installSourcePackage");
00295     hge = fi->hge;
00296     hfd = fi->hfd;
00297 
00298 /*@i@*/ (void) rpmInstallLoadMacros(fi, fi->h);
00299 
00300     psm->fi = rpmfiLink(fi, NULL);
00301     /*@-assignexpose -usereleased @*/
00302     psm->te = fi->te;
00303     /*@=assignexpose =usereleased @*/
00304 
00305     if (cookie) {
00306         *cookie = NULL;
00307         if (hge(fi->h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL))
00308             *cookie = xstrdup(*cookie);
00309     }
00310 
00311     /* XXX FIXME: can't do endian neutral MD5 verification yet. */
00312 /*@i@*/ fi->fmd5s = hfd(fi->fmd5s, -1);
00313 
00314     /* XXX FIXME: don't do per-file mapping, force global flags. */
00315     fi->fmapflags = _free(fi->fmapflags);
00316     fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
00317 
00318     fi->uid = getuid();
00319     fi->gid = getgid();
00320     fi->astriplen = 0;
00321     fi->striplen = 0;
00322 
00323     for (i = 0; i < fi->fc; i++)
00324         fi->actions[i] = FA_CREATE;
00325 
00326     i = fi->fc;
00327 
00328     if (fi->h != NULL) {        /* XXX can't happen */
00329         rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
00330 
00331         if (headerIsEntry(fi->h, RPMTAG_COOKIE))
00332             for (i = 0; i < fi->fc; i++)
00333                 if (fi->fflags[i] & RPMFILE_SPECFILE) break;
00334     }
00335 
00336     if (i == fi->fc) {
00337         /* Find the spec file by name. */
00338         for (i = 0; i < fi->fc; i++) {
00339             const char * t = fi->apath[i];
00340             t += strlen(fi->apath[i]) - 5;
00341             if (!strcmp(t, ".spec")) break;
00342         }
00343     }
00344 
00345     _sourcedir = rpmGenPath(rpmtsRootDir(ts), "%{_sourcedir}", "");
00346     rpmrc = rpmMkdirPath(_sourcedir, "sourcedir");
00347     if (rpmrc) {
00348         rpmrc = RPMRC_FAIL;
00349         goto exit;
00350     }
00351 
00352     _specdir = rpmGenPath(rpmtsRootDir(ts), "%{_specdir}", "");
00353     rpmrc = rpmMkdirPath(_specdir, "specdir");
00354     if (rpmrc) {
00355         rpmrc = RPMRC_FAIL;
00356         goto exit;
00357     }
00358 
00359     /* Build dnl/dil with {_sourcedir, _specdir} as values. */
00360     if (i < fi->fc) {
00361         int speclen = strlen(_specdir) + 2;
00362         int sourcelen = strlen(_sourcedir) + 2;
00363         char * t;
00364 
00365 /*@i@*/ fi->dnl = hfd(fi->dnl, -1);
00366 
00367         fi->dc = 2;
00368         fi->dnl = xmalloc(fi->dc * sizeof(*fi->dnl)
00369                         + fi->fc * sizeof(*fi->dil)
00370                         + speclen + sourcelen);
00371         /*@-dependenttrans@*/
00372         fi->dil = (int *)(fi->dnl + fi->dc);
00373         /*@=dependenttrans@*/
00374         memset(fi->dil, 0, fi->fc * sizeof(*fi->dil));
00375         fi->dil[i] = 1;
00376         /*@-dependenttrans@*/
00377         fi->dnl[0] = t = (char *)(fi->dil + fi->fc);
00378         fi->dnl[1] = t = stpcpy( stpcpy(t, _sourcedir), "/") + 1;
00379         /*@=dependenttrans@*/
00380         (void) stpcpy( stpcpy(t, _specdir), "/");
00381 
00382         t = xmalloc(speclen + strlen(fi->bnl[i]) + 1);
00383         (void) stpcpy( stpcpy( stpcpy(t, _specdir), "/"), fi->bnl[i]);
00384         specFile = t;
00385     } else {
00386         rpmError(RPMERR_NOSPEC, _("source package contains no .spec file\n"));
00387         rpmrc = RPMRC_FAIL;
00388         goto exit;
00389     }
00390 
00391     psm->goal = PSM_PKGINSTALL;
00392 
00393     /*@-compmempass@*/  /* FIX: psm->fi->dnl should be owned. */
00394     rpmrc = rpmpsmStage(psm, PSM_PROCESS);
00395 
00396     (void) rpmpsmStage(psm, PSM_FINI);
00397     /*@=compmempass@*/
00398 
00399     if (rpmrc) rpmrc = RPMRC_FAIL;
00400 
00401 exit:
00402     if (specFilePtr && specFile && rpmrc == RPMRC_OK)
00403         *specFilePtr = specFile;
00404     else
00405         specFile = _free(specFile);
00406 
00407     _specdir = _free(_specdir);
00408     _sourcedir = _free(_sourcedir);
00409 
00410     psm->fi = rpmfiFree(psm->fi);
00411     psm->te = NULL;
00412 
00413     if (h != NULL) h = headerFree(h);
00414 
00415     /*@-branchstate@*/
00416     if (fi != NULL) {
00417         fi->te->h = headerFree(fi->te->h);
00418         if (fi->te->fd != NULL)
00419             (void) Fclose(fi->te->fd);
00420         fi->te->fd = NULL;
00421         fi->te = NULL;
00422         fi = rpmfiFree(fi);
00423     }
00424     /*@=branchstate@*/
00425 
00426     /* XXX nuke the added package(s). */
00427     rpmtsClean(ts);
00428 
00429     psm->ts = rpmtsFree(psm->ts);
00430 
00431     return rpmrc;
00432 }
00433 
00434 /*@observer@*/ /*@unchecked@*/
00435 static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin";
00436 
00442 static /*@observer@*/ const char * const tag2sln(int tag)
00443         /*@*/
00444 {
00445     switch (tag) {
00446     case RPMTAG_PREIN:          return "%pre";
00447     case RPMTAG_POSTIN:         return "%post";
00448     case RPMTAG_PREUN:          return "%preun";
00449     case RPMTAG_POSTUN:         return "%postun";
00450     case RPMTAG_VERIFYSCRIPT:   return "%verify";
00451     }
00452     return "%unknownscript";
00453 }
00454 
00460 static pid_t psmWait(rpmpsm psm)
00461         /*@globals fileSystem, internalState @*/
00462         /*@modifies psm, fileSystem, internalState @*/
00463 {
00464     const rpmts ts = psm->ts;
00465     rpmtime_t msecs;
00466 
00467     (void) rpmsqWait(&psm->sq);
00468     msecs = psm->sq.op.usecs/1000;
00469     (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), &psm->sq.op);
00470 
00471     rpmMessage(RPMMESS_DEBUG,
00472         _("%s: waitpid(%d) rc %d status %x secs %u.%03u\n"),
00473         psm->stepName, (unsigned)psm->sq.child,
00474         (unsigned)psm->sq.reaped, psm->sq.status,
00475         (unsigned)msecs/1000, (unsigned)msecs%1000);
00476 
00477     return psm->sq.reaped;
00478 }
00479 
00482 /*@unchecked@*/
00483 static int ldconfig_done = 0;
00484 
00485 /*@unchecked@*/ /*@observer@*/ /*@null@*/
00486 static const char * ldconfig_path = "/sbin/ldconfig";
00487 
00506 static rpmRC runScript(rpmpsm psm, Header h, const char * sln,
00507                 int progArgc, const char ** progArgv, 
00508                 const char * script, int arg1, int arg2)
00509         /*@globals ldconfig_done, rpmGlobalMacroContext, h_errno,
00510                 fileSystem, internalState@*/
00511         /*@modifies psm, ldconfig_done, rpmGlobalMacroContext,
00512                 fileSystem, internalState @*/
00513 {
00514     const rpmts ts = psm->ts;
00515     rpmfi fi = psm->fi;
00516     HGE_t hge = fi->hge;
00517     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00518     const char ** argv = NULL;
00519     int argc = 0;
00520     const char ** prefixes = NULL;
00521     int numPrefixes;
00522     rpmTagType ipt;
00523     const char * oldPrefix;
00524     int maxPrefixLength;
00525     int len;
00526     char * prefixBuf = NULL;
00527     const char * fn = NULL;
00528     int xx;
00529     int i;
00530     int freePrefixes = 0;
00531     FD_t scriptFd;
00532     FD_t out;
00533     rpmRC rc = RPMRC_OK;
00534     const char *n, *v, *r;
00535 
00536     if (progArgv == NULL && script == NULL)
00537         return rc;
00538 
00539     psm->sq.reaper = 1;
00540 
00541     /* XXX FIXME: except for %verifyscript, rpmteNEVR can be used. */
00542     xx = headerNVR(h, &n, &v, &r);
00543 
00544     /* XXX bash must have functional libtermcap.so.2 */
00545     if (!strcmp(n, "libtermcap"))
00546         ldconfig_done = 0;
00547 
00548     /*
00549      * If a successor node, and ldconfig was just run, don't bother.
00550      */
00551     if (ldconfig_path && progArgv && psm->unorderedSuccessor) {
00552         if (ldconfig_done && !strcmp(progArgv[0], ldconfig_path)) {
00553             rpmMessage(RPMMESS_DEBUG,
00554                 _("%s: %s(%s-%s-%s) skipping redundant \"%s\".\n"),
00555                 psm->stepName, tag2sln(psm->scriptTag), n, v, r,
00556                 progArgv[0]);
00557             return rc;
00558         }
00559     }
00560 
00561     rpmMessage(RPMMESS_DEBUG,
00562                 _("%s: %s(%s-%s-%s) %ssynchronous scriptlet start\n"),
00563                 psm->stepName, tag2sln(psm->scriptTag), n, v, r,
00564                 (psm->unorderedSuccessor ? "a" : ""));
00565 
00566     if (!progArgv) {
00567         argv = alloca(5 * sizeof(*argv));
00568         argv[0] = "/bin/sh";
00569         argc = 1;
00570         ldconfig_done = 0;
00571     } else {
00572         argv = alloca((progArgc + 4) * sizeof(*argv));
00573         memcpy(argv, progArgv, progArgc * sizeof(*argv));
00574         argc = progArgc;
00575         ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path)
00576                 ? 1 : 0);
00577     }
00578 
00579     if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &prefixes, &numPrefixes)) {
00580         freePrefixes = 1;
00581     } else if (hge(h, RPMTAG_INSTALLPREFIX, NULL, (void **) &oldPrefix, NULL)) {
00582         prefixes = &oldPrefix;
00583         numPrefixes = 1;
00584     } else {
00585         numPrefixes = 0;
00586     }
00587 
00588     maxPrefixLength = 0;
00589     if (prefixes != NULL)
00590     for (i = 0; i < numPrefixes; i++) {
00591         len = strlen(prefixes[i]);
00592         if (len > maxPrefixLength) maxPrefixLength = len;
00593     }
00594     prefixBuf = alloca(maxPrefixLength + 50);
00595 
00596     if (script) {
00597         const char * rootDir = rpmtsRootDir(ts);
00598         FD_t fd;
00599 
00600         /*@-branchstate@*/
00601         if (makeTempFile((!rpmtsChrootDone(ts) ? rootDir : "/"), &fn, &fd)) {
00602             if (prefixes != NULL && freePrefixes) free(prefixes);
00603             return RPMRC_FAIL;
00604         }
00605         /*@=branchstate@*/
00606 
00607         if (rpmIsDebug() &&
00608             (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
00609         {
00610             static const char set_x[] = "set -x\n";
00611             xx = Fwrite(set_x, sizeof(set_x[0]), sizeof(set_x)-1, fd);
00612         }
00613 
00614         if (ldconfig_path && strstr(script, ldconfig_path) != NULL)
00615             ldconfig_done = 1;
00616 
00617         xx = Fwrite(script, sizeof(script[0]), strlen(script), fd);
00618         xx = Fclose(fd);
00619 
00620         {   const char * sn = fn;
00621             if (!rpmtsChrootDone(ts) && rootDir != NULL &&
00622                 !(rootDir[0] == '/' && rootDir[1] == '\0'))
00623             {
00624                 sn += strlen(rootDir)-1;
00625             }
00626             argv[argc++] = sn;
00627         }
00628 
00629         if (arg1 >= 0) {
00630             char *av = alloca(20);
00631             sprintf(av, "%d", arg1);
00632             argv[argc++] = av;
00633         }
00634         if (arg2 >= 0) {
00635             char *av = alloca(20);
00636             sprintf(av, "%d", arg2);
00637             argv[argc++] = av;
00638         }
00639     }
00640 
00641     argv[argc] = NULL;
00642 
00643     scriptFd = rpmtsScriptFd(ts);
00644     if (scriptFd != NULL) {
00645         if (rpmIsVerbose()) {
00646             out = fdDup(Fileno(scriptFd));
00647         } else {
00648             out = Fopen("/dev/null", "w.fdio");
00649             if (Ferror(out)) {
00650                 out = fdDup(Fileno(scriptFd));
00651             }
00652         }
00653     } else {
00654         out = fdDup(STDOUT_FILENO);
00655     }
00656     if (out == NULL) return RPMRC_FAIL; /* XXX can't happen */
00657     
00658     /*@-branchstate@*/
00659     xx = rpmsqFork(&psm->sq);
00660     if (psm->sq.child == 0) {
00661         const char * rootDir;
00662         int pipes[2];
00663 
00664         pipes[0] = pipes[1] = 0;
00665         /* make stdin inaccessible */
00666         xx = pipe(pipes);
00667         xx = close(pipes[1]);
00668         xx = dup2(pipes[0], STDIN_FILENO);
00669         xx = close(pipes[0]);
00670 
00671         if (scriptFd != NULL) {
00672             int sfdno = Fileno(scriptFd);
00673             int ofdno = Fileno(out);
00674             if (sfdno != STDERR_FILENO)
00675                 xx = dup2(sfdno, STDERR_FILENO);
00676             if (ofdno != STDOUT_FILENO)
00677                 xx = dup2(ofdno, STDOUT_FILENO);
00678             /* make sure we don't close stdin/stderr/stdout by mistake! */
00679             if (ofdno > STDERR_FILENO && ofdno != sfdno)
00680                 xx = Fclose (out);
00681             if (sfdno > STDERR_FILENO)
00682                 xx = Fclose (scriptFd);
00683             else {
00684 /*@-usereleased@*/
00685                 xx = Fclose(out);
00686 /*@=usereleased@*/
00687             }
00688         }
00689 
00690         {   const char *ipath = rpmExpand("PATH=%{_install_script_path}", NULL);
00691             const char *path = SCRIPT_PATH;
00692 
00693             if (ipath && ipath[5] != '%')
00694                 path = ipath;
00695 
00696             xx = doputenv(path);
00697             /*@-modobserver@*/
00698             ipath = _free(ipath);
00699             /*@=modobserver@*/
00700         }
00701 
00702         if (prefixes != NULL)
00703         for (i = 0; i < numPrefixes; i++) {
00704             sprintf(prefixBuf, "RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
00705             xx = doputenv(prefixBuf);
00706 
00707             /* backwards compatibility */
00708             if (i == 0) {
00709                 sprintf(prefixBuf, "RPM_INSTALL_PREFIX=%s", prefixes[i]);
00710                 xx = doputenv(prefixBuf);
00711             }
00712         }
00713 
00714         rootDir = rpmtsRootDir(ts);
00715         if (rootDir  != NULL)   /* XXX can't happen */
00716         switch(urlIsURL(rootDir)) {
00717         case URL_IS_PATH:
00718             rootDir += sizeof("file://") - 1;
00719             rootDir = strchr(rootDir, '/');
00720             /*@fallthrough@*/
00721         case URL_IS_UNKNOWN:
00722             if (!rpmtsChrootDone(ts) &&
00723                 !(rootDir[0] == '/' && rootDir[1] == '\0'))
00724             {
00725                 /*@-superuser -noeffect @*/
00726                 xx = chroot(rootDir);
00727                 /*@=superuser =noeffect @*/
00728             }
00729             xx = chdir("/");
00730             rpmMessage(RPMMESS_DEBUG, _("%s: %s(%s-%s-%s)\texecv(%s) pid %d\n"),
00731                         psm->stepName, sln, n, v, r,
00732                         argv[0], (unsigned)getpid());
00733             unsetenv("MALLOC_CHECK_");
00734 /*@-nullstate@*/
00735             xx = execv(argv[0], (char *const *)argv);
00736 /*@=nullstate@*/
00737             break;
00738         default:
00739             break;
00740         }
00741 
00742         _exit(-1);
00743         /*@notreached@*/
00744     }
00745     /*@=branchstate@*/
00746 
00747     (void) psmWait(psm);
00748 
00749     if (psm->sq.reaped < 0) {
00750         rpmError(RPMERR_SCRIPT,
00751                 _("%s(%s-%s-%s) scriptlet failed, waitpid(%d) rc %d: %s\n"),
00752                  sln, n, v, r, psm->sq.child, psm->sq.reaped, strerror(errno));
00753         rc = RPMRC_FAIL;
00754     } else
00755     if (!WIFEXITED(psm->sq.status) || WEXITSTATUS(psm->sq.status)) {
00756         rpmError(RPMERR_SCRIPT,
00757                 _("%s(%s-%s-%s) scriptlet failed, exit status %d\n"),
00758                 sln, n, v, r, WEXITSTATUS(psm->sq.status));
00759         rc = RPMRC_FAIL;
00760     }
00761 
00762     if (freePrefixes) prefixes = hfd(prefixes, ipt);
00763 
00764     xx = Fclose(out);   /* XXX dup'd STDOUT_FILENO */
00765     
00766     /*@-branchstate@*/
00767     if (script) {
00768         if (!rpmIsDebug())
00769             xx = unlink(fn);
00770         fn = _free(fn);
00771     }
00772     /*@=branchstate@*/
00773 
00774     return rc;
00775 }
00776 
00782 static rpmRC runInstScript(rpmpsm psm)
00783         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00784         /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
00785 {
00786     rpmfi fi = psm->fi;
00787     HGE_t hge = fi->hge;
00788     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00789     void ** progArgv;
00790     int progArgc;
00791     const char ** argv;
00792     rpmTagType ptt, stt;
00793     const char * script;
00794     rpmRC rc = RPMRC_OK;
00795     int xx;
00796 
00797     /*
00798      * headerGetEntry() sets the data pointer to NULL if the entry does
00799      * not exist.
00800      */
00801     xx = hge(fi->h, psm->scriptTag, &stt, (void **) &script, NULL);
00802     xx = hge(fi->h, psm->progTag, &ptt, (void **) &progArgv, &progArgc);
00803     if (progArgv == NULL && script == NULL)
00804         goto exit;
00805 
00806     /*@-branchstate@*/
00807     if (progArgv && ptt == RPM_STRING_TYPE) {
00808         argv = alloca(sizeof(*argv));
00809         *argv = (const char *) progArgv;
00810     } else {
00811         argv = (const char **) progArgv;
00812     }
00813     /*@=branchstate@*/
00814 
00815     if (fi->h != NULL)  /* XXX can't happen */
00816     rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), progArgc, argv,
00817                 script, psm->scriptArg, -1);
00818 
00819 exit:
00820     progArgv = hfd(progArgv, ptt);
00821     script = hfd(script, stt);
00822     return rc;
00823 }
00824 
00835 static rpmRC handleOneTrigger(const rpmpsm psm,
00836                         Header sourceH, Header triggeredH,
00837                         int arg2, unsigned char * triggersAlreadyRun)
00838         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState@*/
00839         /*@modifies psm, sourceH, triggeredH, *triggersAlreadyRun,
00840                 rpmGlobalMacroContext, fileSystem, internalState @*/
00841 {
00842     int scareMem = 1;
00843     const rpmts ts = psm->ts;
00844     rpmfi fi = psm->fi;
00845     HGE_t hge = fi->hge;
00846     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00847     rpmds trigger = NULL;
00848     const char ** triggerScripts;
00849     const char ** triggerProgs;
00850     int_32 * triggerIndices;
00851     const char * sourceName;
00852     const char * triggerName;
00853     rpmRC rc = RPMRC_OK;
00854     int xx;
00855     int i;
00856 
00857     xx = headerNVR(sourceH, &sourceName, NULL, NULL);
00858     xx = headerNVR(triggeredH, &triggerName, NULL, NULL);
00859 
00860     trigger = rpmdsInit(rpmdsNew(triggeredH, RPMTAG_TRIGGERNAME, scareMem));
00861     if (trigger == NULL)
00862         return rc;
00863 
00864     (void) rpmdsSetNoPromote(trigger, 1);
00865 
00866     while ((i = rpmdsNext(trigger)) >= 0) {
00867         rpmTagType tit, tst, tpt;
00868         const char * Name;
00869         int_32 Flags = rpmdsFlags(trigger);
00870 
00871         if ((Name = rpmdsN(trigger)) == NULL)
00872             continue;   /* XXX can't happen */
00873 
00874         if (strcmp(Name, sourceName))
00875             continue;
00876         if (!(Flags & psm->sense))
00877             continue;
00878 
00879         /*
00880          * XXX Trigger on any provided dependency, not just the package NEVR.
00881          */
00882         if (!rpmdsAnyMatchesDep(sourceH, trigger, 1))
00883             continue;
00884 
00885         if (!(  hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit,
00886                        (void **) &triggerIndices, NULL) &&
00887                 hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst,
00888                        (void **) &triggerScripts, NULL) &&
00889                 hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt,
00890                        (void **) &triggerProgs, NULL))
00891             )
00892             continue;
00893 
00894         {   int arg1;
00895             int index;
00896 
00897             arg1 = rpmdbCountPackages(rpmtsGetRdb(ts), triggerName);
00898             if (arg1 < 0) {
00899                 /* XXX W2DO? fails as "execution of script failed" */
00900                 rc = RPMRC_FAIL;
00901             } else {
00902                 arg1 += psm->countCorrection;
00903                 index = triggerIndices[i];
00904                 if (triggersAlreadyRun == NULL ||
00905                     triggersAlreadyRun[index] == 0)
00906                 {
00907                     rc = runScript(psm, triggeredH, "%trigger", 1,
00908                             triggerProgs + index, triggerScripts[index], 
00909                             arg1, arg2);
00910                     if (triggersAlreadyRun != NULL)
00911                         triggersAlreadyRun[index] = 1;
00912                 }
00913             }
00914         }
00915 
00916         triggerIndices = hfd(triggerIndices, tit);
00917         triggerScripts = hfd(triggerScripts, tst);
00918         triggerProgs = hfd(triggerProgs, tpt);
00919 
00920         /*
00921          * Each target/source header pair can only result in a single
00922          * script being run.
00923          */
00924         break;
00925     }
00926 
00927     trigger = rpmdsFree(trigger);
00928 
00929     return rc;
00930 }
00931 
00937 static rpmRC runTriggers(rpmpsm psm)
00938         /*@globals rpmGlobalMacroContext, h_errno,
00939                 fileSystem, internalState @*/
00940         /*@modifies psm, rpmGlobalMacroContext,
00941                 fileSystem, internalState @*/
00942 {
00943     const rpmts ts = psm->ts;
00944     rpmfi fi = psm->fi;
00945     int numPackage = -1;
00946     rpmRC rc = RPMRC_OK;
00947     const char * N = NULL;
00948 
00949     if (psm->te)        /* XXX can't happen */
00950         N = rpmteN(psm->te);
00951     if (N)              /* XXX can't happen */
00952         numPackage = rpmdbCountPackages(rpmtsGetRdb(ts), N)
00953                                 + psm->countCorrection;
00954     if (numPackage < 0)
00955         return RPMRC_NOTFOUND;
00956 
00957     if (fi != NULL && fi->h != NULL)    /* XXX can't happen */
00958     {   Header triggeredH;
00959         rpmdbMatchIterator mi;
00960         int countCorrection = psm->countCorrection;
00961 
00962         psm->countCorrection = 0;
00963         mi = rpmtsInitIterator(ts, RPMTAG_TRIGGERNAME, N, 0);
00964         while((triggeredH = rpmdbNextIterator(mi)) != NULL)
00965             rc |= handleOneTrigger(psm, fi->h, triggeredH, numPackage, NULL);
00966         mi = rpmdbFreeIterator(mi);
00967         psm->countCorrection = countCorrection;
00968     }
00969 
00970     return rc;
00971 }
00972 
00978 static rpmRC runImmedTriggers(rpmpsm psm)
00979         /*@globals rpmGlobalMacroContext, h_errno,
00980                 fileSystem, internalState @*/
00981         /*@modifies psm, rpmGlobalMacroContext,
00982                 fileSystem, internalState @*/
00983 {
00984     const rpmts ts = psm->ts;
00985     rpmfi fi = psm->fi;
00986     HGE_t hge = fi->hge;
00987     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00988     const char ** triggerNames;
00989     int numTriggers;
00990     int_32 * triggerIndices;
00991     rpmTagType tnt, tit;
00992     int numTriggerIndices;
00993     unsigned char * triggersRun;
00994     rpmRC rc = RPMRC_OK;
00995 
00996     if (fi->h == NULL)  return rc;      /* XXX can't happen */
00997 
00998     if (!(      hge(fi->h, RPMTAG_TRIGGERNAME, &tnt,
00999                         (void **) &triggerNames, &numTriggers) &&
01000                 hge(fi->h, RPMTAG_TRIGGERINDEX, &tit,
01001                         (void **) &triggerIndices, &numTriggerIndices))
01002         )
01003         return rc;
01004 
01005     triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
01006     memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
01007 
01008     {   Header sourceH = NULL;
01009         int i;
01010 
01011         for (i = 0; i < numTriggers; i++) {
01012             rpmdbMatchIterator mi;
01013 
01014             if (triggersRun[triggerIndices[i]] != 0) continue;
01015         
01016             mi = rpmtsInitIterator(ts, RPMTAG_NAME, triggerNames[i], 0);
01017 
01018             while((sourceH = rpmdbNextIterator(mi)) != NULL) {
01019                 rc |= handleOneTrigger(psm, sourceH, fi->h, 
01020                                 rpmdbGetIteratorCount(mi),
01021                                 triggersRun);
01022             }
01023 
01024             mi = rpmdbFreeIterator(mi);
01025         }
01026     }
01027     triggerIndices = hfd(triggerIndices, tit);
01028     triggerNames = hfd(triggerNames, tnt);
01029     return rc;
01030 }
01031 
01032 /*@observer@*/ static const char *const pkgStageString(pkgStage a)
01033         /*@*/
01034 {
01035     switch(a) {
01036     case PSM_UNKNOWN:           return "unknown";
01037 
01038     case PSM_PKGINSTALL:        return "  install";
01039     case PSM_PKGERASE:          return "    erase";
01040     case PSM_PKGCOMMIT:         return "   commit";
01041     case PSM_PKGSAVE:           return "repackage";
01042 
01043     case PSM_INIT:              return "init";
01044     case PSM_PRE:               return "pre";
01045     case PSM_PROCESS:           return "process";
01046     case PSM_POST:              return "post";
01047     case PSM_UNDO:              return "undo";
01048     case PSM_FINI:              return "fini";
01049 
01050     case PSM_CREATE:            return "create";
01051     case PSM_NOTIFY:            return "notify";
01052     case PSM_DESTROY:           return "destroy";
01053     case PSM_COMMIT:            return "commit";
01054 
01055     case PSM_CHROOT_IN:         return "chrootin";
01056     case PSM_CHROOT_OUT:        return "chrootout";
01057     case PSM_SCRIPT:            return "script";
01058     case PSM_TRIGGERS:          return "triggers";
01059     case PSM_IMMED_TRIGGERS:    return "immedtriggers";
01060 
01061     case PSM_RPMIO_FLAGS:       return "rpmioflags";
01062 
01063     case PSM_RPMDB_LOAD:        return "rpmdbload";
01064     case PSM_RPMDB_ADD:         return "rpmdbadd";
01065     case PSM_RPMDB_REMOVE:      return "rpmdbremove";
01066 
01067     default:                    return "???";
01068     }
01069     /*@noteached@*/
01070 }
01071 
01072 rpmpsm XrpmpsmUnlink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
01073 {
01074     if (psm == NULL) return NULL;
01075 /*@-modfilesys@*/
01076 if (_psm_debug && msg != NULL)
01077 fprintf(stderr, "--> psm %p -- %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
01078 /*@=modfilesys@*/
01079     psm->nrefs--;
01080     return NULL;
01081 }
01082 
01083 rpmpsm XrpmpsmLink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
01084 {
01085     if (psm == NULL) return NULL;
01086     psm->nrefs++;
01087 
01088 /*@-modfilesys@*/
01089 if (_psm_debug && msg != NULL)
01090 fprintf(stderr, "--> psm %p ++ %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
01091 /*@=modfilesys@*/
01092 
01093     /*@-refcounttrans@*/ return psm; /*@=refcounttrans@*/
01094 }
01095 
01096 rpmpsm rpmpsmFree(rpmpsm psm)
01097 {
01098     const char * msg = "rpmpsmFree";
01099     if (psm == NULL)
01100         return NULL;
01101 
01102     if (psm->nrefs > 1)
01103         return rpmpsmUnlink(psm, msg);
01104 
01105 /*@-nullstate@*/
01106     psm->fi = rpmfiFree(psm->fi);
01107 #ifdef  NOTYET
01108     psm->te = rpmteFree(psm->te);
01109 #else
01110     psm->te = NULL;
01111 #endif
01112 /*@-internalglobs@*/
01113     psm->ts = rpmtsFree(psm->ts);
01114 /*@=internalglobs@*/
01115 
01116     (void) rpmpsmUnlink(psm, msg);
01117 
01118     /*@-refcounttrans -usereleased@*/
01119 /*@-boundswrite@*/
01120     memset(psm, 0, sizeof(*psm));               /* XXX trash and burn */
01121 /*@=boundswrite@*/
01122     psm = _free(psm);
01123     /*@=refcounttrans =usereleased@*/
01124 
01125     return NULL;
01126 /*@=nullstate@*/
01127 }
01128 
01129 rpmpsm rpmpsmNew(rpmts ts, rpmte te, rpmfi fi)
01130 {
01131     const char * msg = "rpmpsmNew";
01132     rpmpsm psm = xcalloc(1, sizeof(*psm));
01133 
01134     if (ts)     psm->ts = rpmtsLink(ts, msg);
01135 #ifdef  NOTYET
01136     if (te)     psm->te = rpmteLink(te, msg);
01137 #else
01138 /*@-assignexpose -temptrans @*/
01139     if (te)     psm->te = te;
01140 /*@=assignexpose =temptrans @*/
01141 #endif
01142     if (fi)     psm->fi = rpmfiLink(fi, msg);
01143 
01144     return rpmpsmLink(psm, msg);
01145 }
01146 
01147 #if NOTYET
01148 static void * rpmpsmThread(void * arg)
01149         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
01150         /*@modifies arg, rpmGlobalMacroContext, fileSystem, internalState @*/
01151 {
01152     rpmpsm psm = arg;
01153 /*@-unqualifiedtrans@*/
01154     return ((void *) rpmpsmStage(psm, psm->nstage));
01155 /*@=unqualifiedtrans@*/
01156 }
01157 
01158 static int rpmpsmNext(rpmpsm psm, pkgStage nstage)
01159         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
01160         /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
01161 {
01162     psm->nstage = nstage;
01163     if (_psm_threads)
01164         return rpmsqJoin( rpmsqThread(rpmpsmThread, psm) );
01165     return rpmpsmStage(psm, psm->nstage);
01166 }
01167 #endif
01168 
01173 /*@-bounds -nullpass@*/ /* FIX: testing null annotation for fi->h */
01174 rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
01175 {
01176     const rpmts ts = psm->ts;
01177     uint_32 tscolor = rpmtsColor(ts);
01178     rpmfi fi = psm->fi;
01179     HGE_t hge = fi->hge;
01180     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
01181     rpmRC rc = psm->rc;
01182     int saveerrno;
01183     int xx;
01184 
01185     /*@-branchstate@*/
01186     switch (stage) {
01187     case PSM_UNKNOWN:
01188         break;
01189     case PSM_INIT:
01190         rpmMessage(RPMMESS_DEBUG, _("%s: %s has %d files, test = %d\n"),
01191                 psm->stepName, rpmteNEVR(psm->te),
01192                 rpmfiFC(fi), (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST));
01193 
01194         /*
01195          * When we run scripts, we pass an argument which is the number of 
01196          * versions of this package that will be installed when we are
01197          * finished.
01198          */
01199         psm->npkgs_installed = rpmdbCountPackages(rpmtsGetRdb(ts), rpmteN(psm->te));
01200         if (psm->npkgs_installed < 0) {
01201             rc = RPMRC_FAIL;
01202             break;
01203         }
01204 
01205         if (psm->goal == PSM_PKGINSTALL) {
01206             int fc = rpmfiFC(fi);
01207 
01208             psm->scriptArg = psm->npkgs_installed + 1;
01209 
01210 assert(psm->mi == NULL);
01211             psm->mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(psm->te), 0);
01212             xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_EPOCH, RPMMIRE_DEFAULT,
01213                         rpmteE(psm->te));
01214             xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_VERSION, RPMMIRE_DEFAULT,
01215                         rpmteV(psm->te));
01216             xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT,
01217                         rpmteR(psm->te));
01218             if (tscolor) {
01219                 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_ARCH, RPMMIRE_DEFAULT,
01220                         rpmteA(psm->te));
01221                 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_OS, RPMMIRE_DEFAULT,
01222                         rpmteO(psm->te));
01223             }
01224 
01225             while ((psm->oh = rpmdbNextIterator(psm->mi)) != NULL) {
01226                 fi->record = rpmdbGetIteratorOffset(psm->mi);
01227                 psm->oh = NULL;
01228                 /*@loopbreak@*/ break;
01229             }
01230             psm->mi = rpmdbFreeIterator(psm->mi);
01231             rc = RPMRC_OK;
01232 
01233             /* XXX lazy alloc here may need to be done elsewhere. */
01234             if (fi->fstates == NULL && fc > 0) {
01235                 fi->fstates = xmalloc(sizeof(*fi->fstates) * fc);
01236                 memset(fi->fstates, RPMFILE_STATE_NORMAL, fc);
01237             }
01238 
01239             if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)  break;
01240             if (fc <= 0)                                break;
01241         
01242             /*
01243              * Old format relocatable packages need the entire default
01244              * prefix stripped to form the cpio list, while all other packages
01245              * need the leading / stripped.
01246              */
01247             {   const char * p;
01248                 xx = hge(fi->h, RPMTAG_DEFAULTPREFIX, NULL, (void **) &p, NULL);
01249                 fi->striplen = (xx ? strlen(p) + 1 : 1); 
01250             }
01251             fi->mapflags =
01252                 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
01253         
01254             if (headerIsEntry(fi->h, RPMTAG_ORIGBASENAMES))
01255                 rpmfiBuildFNames(fi->h, RPMTAG_ORIGBASENAMES, &fi->apath, NULL);
01256             else
01257                 rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
01258         
01259             if (fi->fuser == NULL)
01260                 xx = hge(fi->h, RPMTAG_FILEUSERNAME, NULL,
01261                                 (void **) &fi->fuser, NULL);
01262             if (fi->fgroup == NULL)
01263                 xx = hge(fi->h, RPMTAG_FILEGROUPNAME, NULL,
01264                                 (void **) &fi->fgroup, NULL);
01265             rc = RPMRC_OK;
01266         }
01267         if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
01268             psm->scriptArg = psm->npkgs_installed - 1;
01269         
01270             /* Retrieve installed header. */
01271             rc = rpmpsmStage(psm, PSM_RPMDB_LOAD);
01272 if (rc == RPMRC_OK)
01273 if (psm->te)
01274 psm->te->h = headerLink(fi->h);
01275         }
01276         if (psm->goal == PSM_PKGSAVE) {
01277             /* Open output package for writing. */
01278             {   const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL);
01279                 const char * pkgbn =
01280                         headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL);
01281 
01282                 bfmt = _free(bfmt);
01283                 psm->pkgURL = rpmGenPath("%{?_repackage_root}",
01284                                          "%{?_repackage_dir}",
01285                                         pkgbn);
01286                 pkgbn = _free(pkgbn);
01287                 (void) urlPath(psm->pkgURL, &psm->pkgfn);
01288                 psm->fd = Fopen(psm->pkgfn, "w.ufdio");
01289                 if (psm->fd == NULL || Ferror(psm->fd)) {
01290                     rc = RPMRC_FAIL;
01291                     break;
01292                 }
01293             }
01294         }
01295         break;
01296     case PSM_PRE:
01297         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01298 
01299 /* XXX insure that trigger index is opened before entering chroot. */
01300 #ifdef  NOTYET
01301  { static int oneshot = 0;
01302    dbiIndex dbi;
01303    if (!oneshot) {
01304      dbi = dbiOpen(rpmtsGetRdb(ts), RPMTAG_TRIGGERNAME, 0);
01305      oneshot++;
01306    }
01307  }
01308 #endif
01309 
01310         /* Change root directory if requested and not already done. */
01311         rc = rpmpsmStage(psm, PSM_CHROOT_IN);
01312 
01313         if (psm->goal == PSM_PKGINSTALL) {
01314             psm->scriptTag = RPMTAG_PREIN;
01315             psm->progTag = RPMTAG_PREINPROG;
01316 
01317             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPREIN)) {
01318                 /* XXX FIXME: implement %triggerprein. */
01319             }
01320 
01321             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPRE)) {
01322                 rc = rpmpsmStage(psm, PSM_SCRIPT);
01323                 if (rc != RPMRC_OK) {
01324                     rpmError(RPMERR_SCRIPT,
01325                         _("%s: %s scriptlet failed (%d), skipping %s\n"),
01326                         psm->stepName, tag2sln(psm->scriptTag), rc,
01327                         rpmteNEVR(psm->te));
01328                     break;
01329                 }
01330             }
01331         }
01332 
01333         if (psm->goal == PSM_PKGERASE) {
01334             psm->scriptTag = RPMTAG_PREUN;
01335             psm->progTag = RPMTAG_PREUNPROG;
01336             psm->sense = RPMSENSE_TRIGGERUN;
01337             psm->countCorrection = -1;
01338 
01339             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERUN)) {
01340                 /* Run triggers in this package other package(s) set off. */
01341                 rc = rpmpsmStage(psm, PSM_IMMED_TRIGGERS);
01342                 if (rc) break;
01343 
01344                 /* Run triggers in other package(s) this package sets off. */
01345                 rc = rpmpsmStage(psm, PSM_TRIGGERS);
01346                 if (rc) break;
01347             }
01348 
01349             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPREUN))
01350                 rc = rpmpsmStage(psm, PSM_SCRIPT);
01351         }
01352         if (psm->goal == PSM_PKGSAVE) {
01353             int noArchiveSize = 0;
01354 
01355             /* Regenerate original header. */
01356             {   void * uh = NULL;
01357                 int_32 uht, uhc;
01358 
01359                 if (headerGetEntry(fi->h, RPMTAG_HEADERIMMUTABLE, &uht, &uh, &uhc)) {
01360                     psm->oh = headerCopyLoad(uh);
01361                     uh = hfd(uh, uht);
01362                 } else
01363                 if (headerGetEntry(fi->h, RPMTAG_HEADERIMAGE, &uht, &uh, &uhc))
01364                 {
01365                     HeaderIterator hi;
01366                     int_32 tag, type, count;
01367                     hPTR_t ptr;
01368                     Header oh;
01369 
01370                     /* Load the original header from the blob. */
01371                     oh = headerCopyLoad(uh);
01372 
01373                     /* XXX this is headerCopy w/o headerReload() */
01374                     psm->oh = headerNew();
01375 
01376                     /*@-branchstate@*/
01377                     for (hi = headerInitIterator(oh);
01378                         headerNextIterator(hi, &tag, &type, &ptr, &count);
01379                         ptr = headerFreeData((void *)ptr, type))
01380                     {
01381                         if (tag == RPMTAG_ARCHIVESIZE)
01382                             noArchiveSize = 1;
01383                         if (ptr) (void) headerAddEntry(psm->oh, tag, type, ptr, count);
01384                     }
01385                     hi = headerFreeIterator(hi);
01386                     /*@=branchstate@*/
01387 
01388                     oh = headerFree(oh);
01389                     uh = hfd(uh, uht);
01390                 } else
01391                     break;      /* XXX shouldn't ever happen */
01392             }
01393 
01394             /* Retrieve type of payload compression. */
01395             /*@-nullstate@*/    /* FIX: psm->oh may be NULL */
01396             rc = rpmpsmStage(psm, PSM_RPMIO_FLAGS);
01397             /*@=nullstate@*/
01398 
01399             /* Write the lead section into the package. */
01400             {   int archnum = -1;
01401                 int osnum = -1;
01402                 struct rpmlead lead;
01403 
01404 #ifndef DYING
01405                 rpmGetArchInfo(NULL, &archnum);
01406                 rpmGetOsInfo(NULL, &osnum);
01407 #endif
01408 
01409                 memset(&lead, 0, sizeof(lead));
01410                 /* XXX Set package version conditioned on noDirTokens. */
01411                 lead.major = 3;
01412                 lead.minor = 0;
01413                 lead.type = RPMLEAD_BINARY;
01414                 lead.archnum = archnum;
01415                 lead.osnum = osnum;
01416                 lead.signature_type = RPMSIGTYPE_HEADERSIG;
01417 
01418                 strncpy(lead.name, rpmteNEVR(psm->te), sizeof(lead.name));
01419 
01420                 rc = writeLead(psm->fd, &lead);
01421                 if (rc != RPMRC_OK) {
01422                     rpmError(RPMERR_NOSPACE, _("Unable to write package: %s\n"),
01423                          Fstrerror(psm->fd));
01424                     break;
01425                 }
01426             }
01427 
01428             /* Write the signature section into the package. */
01429             /* XXX rpm-4.1 and later has archive size in signature header. */
01430             {   Header sigh = headerRegenSigHeader(fi->h, noArchiveSize);
01431                 /* Reallocate the signature into one contiguous region. */
01432                 sigh = headerReload(sigh, RPMTAG_HEADERSIGNATURES);
01433                 if (sigh == NULL) {
01434                     rpmError(RPMERR_NOSPACE, _("Unable to reload signature header\n"));
01435                     rc = RPMRC_FAIL;
01436                     break;
01437                 }
01438                 rc = rpmWriteSignature(psm->fd, sigh);
01439                 sigh = rpmFreeSignature(sigh);
01440                 if (rc) break;
01441             }
01442 
01443             /* Add remove transaction id to header. */
01444             if (psm->oh != NULL)
01445             {   int_32 tid = rpmtsGetTid(ts);
01446                 xx = headerAddEntry(psm->oh, RPMTAG_REMOVETID,
01447                         RPM_INT32_TYPE, &tid, 1);
01448             }
01449 
01450             /* Write the metadata section into the package. */
01451             rc = headerWrite(psm->fd, psm->oh, HEADER_MAGIC_YES);
01452             if (rc) break;
01453         }
01454         break;
01455     case PSM_PROCESS:
01456         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01457 
01458         if (psm->goal == PSM_PKGINSTALL) {
01459 
01460             if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)  break;
01461 
01462             /* XXX Synthesize callbacks for packages with no files. */
01463             if (rpmfiFC(fi) <= 0) {
01464                 void * ptr;
01465                 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_START, 0, 100);
01466                 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, 100, 100);
01467                 break;
01468             }
01469 
01470             /* Retrieve type of payload compression. */
01471             rc = rpmpsmStage(psm, PSM_RPMIO_FLAGS);
01472 
01473             if (rpmteFd(fi->te) == NULL) {      /* XXX can't happen */
01474                 rc = RPMRC_FAIL;
01475                 break;
01476             }
01477 
01478             /*@-nullpass@*/     /* LCL: fi->fd != NULL here. */
01479             psm->cfd = Fdopen(fdDup(Fileno(rpmteFd(fi->te))), psm->rpmio_flags);
01480             /*@=nullpass@*/
01481             if (psm->cfd == NULL) {     /* XXX can't happen */
01482                 rc = RPMRC_FAIL;
01483                 break;
01484             }
01485 
01486             rc = fsmSetup(fi->fsm, FSM_PKGINSTALL, ts, fi,
01487                         psm->cfd, NULL, &psm->failedFile);
01488             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_UNCOMPRESS),
01489                         fdstat_op(psm->cfd, FDSTAT_READ));
01490             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
01491                         fdstat_op(psm->cfd, FDSTAT_DIGEST));
01492             xx = fsmTeardown(fi->fsm);
01493 
01494             saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
01495             xx = Fclose(psm->cfd);
01496             psm->cfd = NULL;
01497             /*@-mods@*/
01498             errno = saveerrno; /* XXX FIXME: Fclose with libio destroys errno */
01499             /*@=mods@*/
01500 
01501             if (!rc)
01502                 rc = rpmpsmStage(psm, PSM_COMMIT);
01503 
01504             /* XXX make sure progress is closed out */
01505             psm->what = RPMCALLBACK_INST_PROGRESS;
01506             psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
01507             psm->total = psm->amount;
01508             xx = rpmpsmStage(psm, PSM_NOTIFY);
01509 
01510             if (rc) {
01511                 rpmError(RPMERR_CPIO,
01512                         _("unpacking of archive failed%s%s: %s\n"),
01513                         (psm->failedFile != NULL ? _(" on file ") : ""),
01514                         (psm->failedFile != NULL ? psm->failedFile : ""),
01515                         cpioStrerror(rc));
01516                 rc = RPMRC_FAIL;
01517 
01518                 /* XXX notify callback on error. */
01519                 psm->what = RPMCALLBACK_UNPACK_ERROR;
01520                 psm->amount = 0;
01521                 psm->total = 0;
01522                 xx = rpmpsmStage(psm, PSM_NOTIFY);
01523 
01524                 break;
01525             }
01526         }
01527         if (psm->goal == PSM_PKGERASE) {
01528             int fc = rpmfiFC(fi);
01529 
01530             if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)  break;
01531             if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY)       break;
01532             if (fc <= 0)                                break;
01533 
01534             psm->what = RPMCALLBACK_UNINST_START;
01535             psm->amount = fc;           /* XXX W2DO? looks wrong. */
01536             psm->total = fc;
01537             xx = rpmpsmStage(psm, PSM_NOTIFY);
01538 
01539             rc = fsmSetup(fi->fsm, FSM_PKGERASE, ts, fi,
01540                         NULL, NULL, &psm->failedFile);
01541             xx = fsmTeardown(fi->fsm);
01542 
01543             psm->what = RPMCALLBACK_UNINST_STOP;
01544             psm->amount = 0;            /* XXX W2DO? looks wrong. */
01545             psm->total = fc;
01546             xx = rpmpsmStage(psm, PSM_NOTIFY);
01547 
01548         }
01549         if (psm->goal == PSM_PKGSAVE) {
01550             fileAction * actions = fi->actions;
01551             fileAction action = fi->action;
01552 
01553             fi->action = FA_COPYOUT;
01554             fi->actions = NULL;
01555 
01556             if (psm->fd == NULL) {      /* XXX can't happen */
01557                 rc = RPMRC_FAIL;
01558                 break;
01559             }
01560             /*@-nullpass@*/     /* FIX: fdDup mey return NULL. */
01561             xx = Fflush(psm->fd);
01562             psm->cfd = Fdopen(fdDup(Fileno(psm->fd)), psm->rpmio_flags);
01563             /*@=nullpass@*/
01564             if (psm->cfd == NULL) {     /* XXX can't happen */
01565                 rc = RPMRC_FAIL;
01566                 break;
01567             }
01568 
01569             rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, psm->cfd,
01570                         NULL, &psm->failedFile);
01571             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_COMPRESS),
01572                         fdstat_op(psm->cfd, FDSTAT_WRITE));
01573             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
01574                         fdstat_op(psm->cfd, FDSTAT_DIGEST));
01575             xx = fsmTeardown(fi->fsm);
01576 
01577             saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
01578             xx = Fclose(psm->cfd);
01579             psm->cfd = NULL;
01580             /*@-mods@*/
01581             errno = saveerrno;
01582             /*@=mods@*/
01583 
01584             /* XXX make sure progress is closed out */
01585             psm->what = RPMCALLBACK_INST_PROGRESS;
01586             psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
01587             psm->total = psm->amount;
01588             xx = rpmpsmStage(psm, PSM_NOTIFY);
01589 
01590             fi->action = action;
01591             fi->actions = actions;
01592         }
01593         break;
01594     case PSM_POST:
01595         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01596 
01597         if (psm->goal == PSM_PKGINSTALL) {
01598             int_32 installTime = (int_32) time(NULL);
01599             int fc = rpmfiFC(fi);
01600 
01601             if (fi->h == NULL) break;   /* XXX can't happen */
01602             if (fi->fstates != NULL && fc > 0)
01603                 xx = headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE,
01604                                 fi->fstates, fc);
01605 
01606             xx = headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
01607                                 &installTime, 1);
01608 
01609             xx = headerAddEntry(fi->h, RPMTAG_INSTALLCOLOR, RPM_INT32_TYPE,
01610                                 &tscolor, 1);
01611 
01612             /*
01613              * If this package has already been installed, remove it from
01614              * the database before adding the new one.
01615              */
01616             if (fi->record && !(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY)) {
01617                 rc = rpmpsmStage(psm, PSM_RPMDB_REMOVE);
01618                 if (rc) break;
01619             }
01620 
01621             rc = rpmpsmStage(psm, PSM_RPMDB_ADD);
01622             if (rc) break;
01623 
01624             psm->scriptTag = RPMTAG_POSTIN;
01625             psm->progTag = RPMTAG_POSTINPROG;
01626             psm->sense = RPMSENSE_TRIGGERIN;
01627             psm->countCorrection = 0;
01628 
01629             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOST)) {
01630                 rc = rpmpsmStage(psm, PSM_SCRIPT);
01631                 if (rc) break;
01632             }
01633             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERIN)) {
01634                 /* Run triggers in other package(s) this package sets off. */
01635                 rc = rpmpsmStage(psm, PSM_TRIGGERS);
01636                 if (rc) break;
01637 
01638                 /* Run triggers in this package other package(s) set off. */
01639                 rc = rpmpsmStage(psm, PSM_IMMED_TRIGGERS);
01640                 if (rc) break;
01641             }
01642 
01643             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
01644                 rc = markReplacedFiles(psm);
01645 
01646         }
01647         if (psm->goal == PSM_PKGERASE) {
01648 
01649             psm->scriptTag = RPMTAG_POSTUN;
01650             psm->progTag = RPMTAG_POSTUNPROG;
01651             psm->sense = RPMSENSE_TRIGGERPOSTUN;
01652             psm->countCorrection = -1;
01653 
01654             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOSTUN)) {
01655                 rc = rpmpsmStage(psm, PSM_SCRIPT);
01656                 /* XXX WTFO? postun failures don't cause erasure failure. */
01657             }
01658 
01659             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPOSTUN)) {
01660                 /* Run triggers in other package(s) this package sets off. */
01661                 rc = rpmpsmStage(psm, PSM_TRIGGERS);
01662                 if (rc) break;
01663             }
01664 
01665             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
01666                 rc = rpmpsmStage(psm, PSM_RPMDB_REMOVE);
01667         }
01668         if (psm->goal == PSM_PKGSAVE) {
01669         }
01670 
01671         /* Restore root directory if changed. */
01672         xx = rpmpsmStage(psm, PSM_CHROOT_OUT);
01673         break;
01674     case PSM_UNDO:
01675         break;
01676     case PSM_FINI:
01677         /* Restore root directory if changed. */
01678         xx = rpmpsmStage(psm, PSM_CHROOT_OUT);
01679 
01680         if (psm->fd != NULL) {
01681             saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
01682             xx = Fclose(psm->fd);
01683             psm->fd = NULL;
01684             /*@-mods@*/
01685             errno = saveerrno;
01686             /*@=mods@*/
01687         }
01688 
01689         if (psm->goal == PSM_PKGSAVE) {
01690             if (!rc && ts && ts->notify == NULL) {
01691                 rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"),
01692                         (psm->pkgURL ? psm->pkgURL : "???"));
01693             }
01694         }
01695 
01696         if (rc) {
01697             if (psm->failedFile)
01698                 rpmError(RPMERR_CPIO,
01699                         _("%s failed on file %s: %s\n"),
01700                         psm->stepName, psm->failedFile, cpioStrerror(rc));
01701             else
01702                 rpmError(RPMERR_CPIO, _("%s failed: %s\n"),
01703                         psm->stepName, cpioStrerror(rc));
01704 
01705             /* XXX notify callback on error. */
01706             psm->what = RPMCALLBACK_CPIO_ERROR;
01707             psm->amount = 0;
01708             psm->total = 0;
01709             /*@-nullstate@*/ /* FIX: psm->fd may be NULL. */
01710             xx = rpmpsmStage(psm, PSM_NOTIFY);
01711             /*@=nullstate@*/
01712         }
01713 
01714 /*@-branchstate@*/
01715         if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
01716 if (psm->te != NULL)
01717 if (psm->te->h != NULL)
01718 psm->te->h = headerFree(psm->te->h);
01719             if (fi->h != NULL)
01720                 fi->h = headerFree(fi->h);
01721         }
01722 /*@=branchstate@*/
01723         psm->oh = headerFree(psm->oh);
01724         psm->pkgURL = _free(psm->pkgURL);
01725         psm->rpmio_flags = _free(psm->rpmio_flags);
01726         psm->failedFile = _free(psm->failedFile);
01727 
01728         fi->fgroup = hfd(fi->fgroup, -1);
01729         fi->fuser = hfd(fi->fuser, -1);
01730         fi->apath = _free(fi->apath);
01731         fi->fstates = _free(fi->fstates);
01732         break;
01733 
01734     case PSM_PKGINSTALL:
01735     case PSM_PKGERASE:
01736     case PSM_PKGSAVE:
01737         psm->goal = stage;
01738         psm->rc = RPMRC_OK;
01739         psm->stepName = pkgStageString(stage);
01740 
01741         rc = rpmpsmStage(psm, PSM_INIT);
01742         if (!rc) rc = rpmpsmStage(psm, PSM_PRE);
01743         if (!rc) rc = rpmpsmStage(psm, PSM_PROCESS);
01744         if (!rc) rc = rpmpsmStage(psm, PSM_POST);
01745         xx = rpmpsmStage(psm, PSM_FINI);
01746         break;
01747     case PSM_PKGCOMMIT:
01748         break;
01749 
01750     case PSM_CREATE:
01751         break;
01752     case PSM_NOTIFY:
01753     {   void * ptr;
01754 /*@-nullpass@*/ /* FIX: psm->te may be NULL */
01755         ptr = rpmtsNotify(ts, psm->te, psm->what, psm->amount, psm->total);
01756 /*@-nullpass@*/
01757     }   break;
01758     case PSM_DESTROY:
01759         break;
01760     case PSM_COMMIT:
01761         if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_PKGCOMMIT)) break;
01762         if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY) break;
01763 
01764         rc = fsmSetup(fi->fsm, FSM_PKGCOMMIT, ts, fi,
01765                         NULL, NULL, &psm->failedFile);
01766         xx = fsmTeardown(fi->fsm);
01767         break;
01768 
01769     case PSM_CHROOT_IN:
01770     {   const char * rootDir = rpmtsRootDir(ts);
01771         /* Change root directory if requested and not already done. */
01772         if (rootDir != NULL && !(rootDir[0] == '/' && rootDir[1] == '\0')
01773          && !rpmtsChrootDone(ts) && !psm->chrootDone)
01774         {
01775             static int _loaded = 0;
01776 
01777             /*
01778              * This loads all of the name services libraries, in case we
01779              * don't have access to them in the chroot().
01780              */
01781             if (!_loaded) {
01782                 (void)getpwnam("root");
01783                 endpwent();
01784                 _loaded++;
01785             }
01786 
01787             xx = chdir("/");
01788             /*@-superuser@*/
01789             rc = chroot(rootDir);
01790             /*@=superuser@*/
01791             psm->chrootDone = 1;
01792             (void) rpmtsSetChrootDone(ts, 1);
01793         }
01794     }   break;
01795     case PSM_CHROOT_OUT:
01796         /* Restore root directory if changed. */
01797         if (psm->chrootDone) {
01798             const char * currDir = rpmtsCurrDir(ts);
01799             /*@-superuser@*/
01800             rc = chroot(".");
01801             /*@=superuser@*/
01802             psm->chrootDone = 0;
01803             (void) rpmtsSetChrootDone(ts, 0);
01804             if (currDir != NULL)        /* XXX can't happen */
01805                 xx = chdir(currDir);
01806         }
01807         break;
01808     case PSM_SCRIPT:    /* Run current package scriptlets. */
01809         rc = runInstScript(psm);
01810         break;
01811     case PSM_TRIGGERS:
01812         /* Run triggers in other package(s) this package sets off. */
01813         rc = runTriggers(psm);
01814         break;
01815     case PSM_IMMED_TRIGGERS:
01816         /* Run triggers in this package other package(s) set off. */
01817         rc = runImmedTriggers(psm);
01818         break;
01819 
01820     case PSM_RPMIO_FLAGS:
01821     {   const char * payload_compressor = NULL;
01822         char * t;
01823 
01824         /*@-branchstate@*/
01825         if (!hge(fi->h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
01826                             (void **) &payload_compressor, NULL))
01827             payload_compressor = "gzip";
01828         /*@=branchstate@*/
01829         psm->rpmio_flags = t = xmalloc(sizeof("w9.gzdio"));
01830         *t = '\0';
01831         t = stpcpy(t, ((psm->goal == PSM_PKGSAVE) ? "w9" : "r"));
01832         if (!strcmp(payload_compressor, "gzip"))
01833             t = stpcpy(t, ".gzdio");
01834         if (!strcmp(payload_compressor, "bzip2"))
01835             t = stpcpy(t, ".bzdio");
01836         rc = RPMRC_OK;
01837     }   break;
01838 
01839     case PSM_RPMDB_LOAD:
01840 assert(psm->mi == NULL);
01841         psm->mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
01842                                 &fi->record, sizeof(fi->record));
01843 
01844         fi->h = rpmdbNextIterator(psm->mi);
01845         if (fi->h != NULL)
01846             fi->h = headerLink(fi->h);
01847 
01848         psm->mi = rpmdbFreeIterator(psm->mi);
01849         rc = (fi->h != NULL ? RPMRC_OK : RPMRC_FAIL);
01850         break;
01851     case PSM_RPMDB_ADD:
01852         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01853         if (fi->h == NULL)      break;  /* XXX can't happen */
01854         (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
01855         if (!(rpmtsVSFlags(ts) & RPMVSF_NOHDRCHK))
01856             rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
01857                                 ts, headerCheck);
01858         else
01859             rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
01860                                 NULL, NULL);
01861         (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
01862         break;
01863     case PSM_RPMDB_REMOVE:
01864         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01865         (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
01866         rc = rpmdbRemove(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->record,
01867                                 NULL, NULL);
01868         (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
01869         break;
01870 
01871     default:
01872         break;
01873 /*@i@*/    }
01874     /*@=branchstate@*/
01875 
01876     /*@-nullstate@*/    /* FIX: psm->oh and psm->fi->h may be NULL. */
01877     return rc;
01878     /*@=nullstate@*/
01879 }
01880 /*@=bounds =nullpass@*/

Generated on Wed May 12 21:09:53 2004 for rpm by doxygen1.2.18