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

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, *a;
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     xx = hge(h, RPMTAG_ARCH, NULL, (void **) &a, NULL);
00544 
00545     /* XXX bash must have functional libtermcap.so.2 */
00546     if (!strcmp(n, "libtermcap"))
00547         ldconfig_done = 0;
00548 
00549     /*
00550      * If a successor node, and ldconfig was just run, don't bother.
00551      */
00552     if (ldconfig_path && progArgv && psm->unorderedSuccessor) {
00553         if (ldconfig_done && !strcmp(progArgv[0], ldconfig_path)) {
00554             rpmMessage(RPMMESS_DEBUG,
00555                 _("%s: %s(%s-%s-%s.%s) skipping redundant \"%s\".\n"),
00556                 psm->stepName, tag2sln(psm->scriptTag), n, v, r, a,
00557                 progArgv[0]);
00558             return rc;
00559         }
00560     }
00561 
00562     rpmMessage(RPMMESS_DEBUG,
00563                 _("%s: %s(%s-%s-%s.%s) %ssynchronous scriptlet start\n"),
00564                 psm->stepName, tag2sln(psm->scriptTag), n, v, r, a,
00565                 (psm->unorderedSuccessor ? "a" : ""));
00566 
00567     if (!progArgv) {
00568         argv = alloca(5 * sizeof(*argv));
00569         argv[0] = "/bin/sh";
00570         argc = 1;
00571         ldconfig_done = 0;
00572     } else {
00573         argv = alloca((progArgc + 4) * sizeof(*argv));
00574         memcpy(argv, progArgv, progArgc * sizeof(*argv));
00575         argc = progArgc;
00576         ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path)
00577                 ? 1 : 0);
00578     }
00579 
00580 #if __ia64__
00581     /* XXX This assumes that all interpreters are elf executables. */
00582     if ((a != NULL && a[0] == 'i' && a[1] != '\0' && a[2] == '8' && a[3] == '6')
00583      && strcmp(argv[0], "/sbin/ldconfig"))
00584     {
00585         const char * fmt = rpmGetPath("%{?_autorelocate_path}", NULL);
00586         const char * errstr;
00587         char * newPath;
00588         char * t;
00589 
00590         newPath = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
00591         fmt = _free(fmt);
00592 
00593         /* XXX On ia64, change leading /emul/ix86 -> /emul/ia32, ick. */
00594         if (newPath != NULL && *newPath != '\0'
00595          && strlen(newPath) >= (sizeof("/emul/i386")-1)
00596          && newPath[0] == '/' && newPath[1] == 'e' && newPath[2] == 'm'
00597          && newPath[3] == 'u' && newPath[4] == 'l' && newPath[5] == '/'
00598          && newPath[6] == 'i' && newPath[8] == '8' && newPath[9] == '6')
00599         {
00600             newPath[7] = 'a';
00601             newPath[8] = '3';
00602             newPath[9] = '2';
00603         }
00604 
00605         t = alloca(strlen(newPath) + strlen(argv[0]) + 1);
00606         *t = '\0';
00607         (void) stpcpy( stpcpy(t, newPath), argv[0]);
00608         newPath = _free(newPath);
00609         argv[0] = t;
00610     }
00611 #endif
00612 
00613     if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &prefixes, &numPrefixes)) {
00614         freePrefixes = 1;
00615     } else if (hge(h, RPMTAG_INSTALLPREFIX, NULL, (void **) &oldPrefix, NULL)) {
00616         prefixes = &oldPrefix;
00617         numPrefixes = 1;
00618     } else {
00619         numPrefixes = 0;
00620     }
00621 
00622     maxPrefixLength = 0;
00623     if (prefixes != NULL)
00624     for (i = 0; i < numPrefixes; i++) {
00625         len = strlen(prefixes[i]);
00626         if (len > maxPrefixLength) maxPrefixLength = len;
00627     }
00628     prefixBuf = alloca(maxPrefixLength + 50);
00629 
00630     if (script) {
00631         const char * rootDir = rpmtsRootDir(ts);
00632         FD_t fd;
00633 
00634         /*@-branchstate@*/
00635         if (makeTempFile((!rpmtsChrootDone(ts) ? rootDir : "/"), &fn, &fd)) {
00636             if (prefixes != NULL && freePrefixes) free(prefixes);
00637             return RPMRC_FAIL;
00638         }
00639         /*@=branchstate@*/
00640 
00641         if (rpmIsDebug() &&
00642             (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
00643         {
00644             static const char set_x[] = "set -x\n";
00645             xx = Fwrite(set_x, sizeof(set_x[0]), sizeof(set_x)-1, fd);
00646         }
00647 
00648         if (ldconfig_path && strstr(script, ldconfig_path) != NULL)
00649             ldconfig_done = 1;
00650 
00651         xx = Fwrite(script, sizeof(script[0]), strlen(script), fd);
00652         xx = Fclose(fd);
00653 
00654         {   const char * sn = fn;
00655             if (!rpmtsChrootDone(ts) && rootDir != NULL &&
00656                 !(rootDir[0] == '/' && rootDir[1] == '\0'))
00657             {
00658                 sn += strlen(rootDir)-1;
00659             }
00660             argv[argc++] = sn;
00661         }
00662 
00663         if (arg1 >= 0) {
00664             char *av = alloca(20);
00665             sprintf(av, "%d", arg1);
00666             argv[argc++] = av;
00667         }
00668         if (arg2 >= 0) {
00669             char *av = alloca(20);
00670             sprintf(av, "%d", arg2);
00671             argv[argc++] = av;
00672         }
00673     }
00674 
00675     argv[argc] = NULL;
00676 
00677     scriptFd = rpmtsScriptFd(ts);
00678     if (scriptFd != NULL) {
00679         if (rpmIsVerbose()) {
00680             out = fdDup(Fileno(scriptFd));
00681         } else {
00682             out = Fopen("/dev/null", "w.fdio");
00683             if (Ferror(out)) {
00684                 out = fdDup(Fileno(scriptFd));
00685             }
00686         }
00687     } else {
00688         out = fdDup(STDOUT_FILENO);
00689     }
00690     if (out == NULL) return RPMRC_FAIL; /* XXX can't happen */
00691     
00692     /*@-branchstate@*/
00693     xx = rpmsqFork(&psm->sq);
00694     if (psm->sq.child == 0) {
00695         const char * rootDir;
00696         int pipes[2];
00697         int flag;
00698         int fdno;
00699 
00700         pipes[0] = pipes[1] = 0;
00701         /* make stdin inaccessible */
00702         xx = pipe(pipes);
00703         xx = close(pipes[1]);
00704         xx = dup2(pipes[0], STDIN_FILENO);
00705         xx = close(pipes[0]);
00706 
00707         /* XXX Force FD_CLOEXEC on 1st 100 inherited fdno's. */
00708         for (fdno = 3; fdno < 100; fdno++) {
00709             flag = fcntl(fdno, F_GETFD);
00710             if (flag == -1 || (flag & FD_CLOEXEC))
00711                 continue;
00712             xx = fcntl(fdno, F_SETFD, FD_CLOEXEC);
00713             /* XXX W2DO? debug msg for inheirited fdno w/o FD_CLOEXEC */
00714         }
00715 
00716         if (scriptFd != NULL) {
00717             int sfdno = Fileno(scriptFd);
00718             int ofdno = Fileno(out);
00719             if (sfdno != STDERR_FILENO)
00720                 xx = dup2(sfdno, STDERR_FILENO);
00721             if (ofdno != STDOUT_FILENO)
00722                 xx = dup2(ofdno, STDOUT_FILENO);
00723             /* make sure we don't close stdin/stderr/stdout by mistake! */
00724             if (ofdno > STDERR_FILENO && ofdno != sfdno)
00725                 xx = Fclose (out);
00726             if (sfdno > STDERR_FILENO)
00727                 xx = Fclose (scriptFd);
00728             else {
00729 /*@-usereleased@*/
00730                 xx = Fclose(out);
00731 /*@=usereleased@*/
00732             }
00733         }
00734 
00735         {   const char *ipath = rpmExpand("PATH=%{_install_script_path}", NULL);
00736             const char *path = SCRIPT_PATH;
00737 
00738             if (ipath && ipath[5] != '%')
00739                 path = ipath;
00740 
00741             xx = doputenv(path);
00742             /*@-modobserver@*/
00743             ipath = _free(ipath);
00744             /*@=modobserver@*/
00745         }
00746 
00747         if (prefixes != NULL)
00748         for (i = 0; i < numPrefixes; i++) {
00749             sprintf(prefixBuf, "RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
00750             xx = doputenv(prefixBuf);
00751 
00752             /* backwards compatibility */
00753             if (i == 0) {
00754                 sprintf(prefixBuf, "RPM_INSTALL_PREFIX=%s", prefixes[i]);
00755                 xx = doputenv(prefixBuf);
00756             }
00757         }
00758 
00759         rootDir = rpmtsRootDir(ts);
00760         if (rootDir  != NULL)   /* XXX can't happen */
00761         switch(urlIsURL(rootDir)) {
00762         case URL_IS_PATH:
00763             rootDir += sizeof("file://") - 1;
00764             rootDir = strchr(rootDir, '/');
00765             /*@fallthrough@*/
00766         case URL_IS_UNKNOWN:
00767             if (!rpmtsChrootDone(ts) &&
00768                 !(rootDir[0] == '/' && rootDir[1] == '\0'))
00769             {
00770                 /*@-superuser -noeffect @*/
00771                 xx = chroot(rootDir);
00772                 /*@=superuser =noeffect @*/
00773             }
00774             xx = chdir("/");
00775             rpmMessage(RPMMESS_DEBUG, _("%s: %s(%s-%s-%s.%s)\texecv(%s) pid %d\n"),
00776                         psm->stepName, sln, n, v, r, a,
00777                         argv[0], (unsigned)getpid());
00778 
00779             /* XXX Don't mtrace into children. */
00780             unsetenv("MALLOC_CHECK_");
00781 
00782             /* Permit libselinux to do the scriptlet exec. */
00783             if (rpmtsSELinuxEnabled(ts) == 1) {
00784                 xx = rpm_execcon(0, argv[0], argv, environ);
00785                 if (xx != 0)
00786                     break;
00787             }
00788 
00789 /*@-nullstate@*/
00790             xx = execv(argv[0], (char *const *)argv);
00791 /*@=nullstate@*/
00792             break;
00793         default:
00794             break;
00795         }
00796 
00797         _exit(-1);
00798         /*@notreached@*/
00799     }
00800     /*@=branchstate@*/
00801 
00802     (void) psmWait(psm);
00803 
00804   /* XXX filter order dependent multilib "other" arch helper error. */
00805   if (!(psm->sq.reaped >= 0 && !strcmp(argv[0], "/usr/sbin/glibc_post_upgrade") && WEXITSTATUS(psm->sq.status) == 110)) {
00806     if (psm->sq.reaped < 0) {
00807         rpmError(RPMERR_SCRIPT,
00808                 _("%s(%s-%s-%s.%s) scriptlet failed, waitpid(%d) rc %d: %s\n"),
00809                  sln, n, v, r, a, psm->sq.child, psm->sq.reaped, strerror(errno));
00810         rc = RPMRC_FAIL;
00811     } else
00812     if (!WIFEXITED(psm->sq.status) || WEXITSTATUS(psm->sq.status)) {
00813         rpmError(RPMERR_SCRIPT,
00814                 _("%s(%s-%s-%s.%s) scriptlet failed, exit status %d\n"),
00815                 sln, n, v, r, a, WEXITSTATUS(psm->sq.status));
00816         rc = RPMRC_FAIL;
00817     }
00818   }
00819 
00820     if (freePrefixes) prefixes = hfd(prefixes, ipt);
00821 
00822     xx = Fclose(out);   /* XXX dup'd STDOUT_FILENO */
00823     
00824     /*@-branchstate@*/
00825     if (script) {
00826         if (!rpmIsDebug())
00827             xx = unlink(fn);
00828         fn = _free(fn);
00829     }
00830     /*@=branchstate@*/
00831 
00832     return rc;
00833 }
00834 
00840 static rpmRC runInstScript(rpmpsm psm)
00841         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00842         /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
00843 {
00844     rpmfi fi = psm->fi;
00845     HGE_t hge = fi->hge;
00846     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00847     void ** progArgv;
00848     int progArgc;
00849     const char ** argv;
00850     rpmTagType ptt, stt;
00851     const char * script;
00852     rpmRC rc = RPMRC_OK;
00853     int xx;
00854 
00855     /*
00856      * headerGetEntry() sets the data pointer to NULL if the entry does
00857      * not exist.
00858      */
00859     xx = hge(fi->h, psm->scriptTag, &stt, (void **) &script, NULL);
00860     xx = hge(fi->h, psm->progTag, &ptt, (void **) &progArgv, &progArgc);
00861     if (progArgv == NULL && script == NULL)
00862         goto exit;
00863 
00864     /*@-branchstate@*/
00865     if (progArgv && ptt == RPM_STRING_TYPE) {
00866         argv = alloca(sizeof(*argv));
00867         *argv = (const char *) progArgv;
00868     } else {
00869         argv = (const char **) progArgv;
00870     }
00871     /*@=branchstate@*/
00872 
00873     if (fi->h != NULL)  /* XXX can't happen */
00874     rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), progArgc, argv,
00875                 script, psm->scriptArg, -1);
00876 
00877 exit:
00878     progArgv = hfd(progArgv, ptt);
00879     script = hfd(script, stt);
00880     return rc;
00881 }
00882 
00893 static rpmRC handleOneTrigger(const rpmpsm psm,
00894                         Header sourceH, Header triggeredH,
00895                         int arg2, unsigned char * triggersAlreadyRun)
00896         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState@*/
00897         /*@modifies psm, sourceH, triggeredH, *triggersAlreadyRun,
00898                 rpmGlobalMacroContext, fileSystem, internalState @*/
00899 {
00900     int scareMem = 1;
00901     const rpmts ts = psm->ts;
00902     rpmfi fi = psm->fi;
00903     HGE_t hge = fi->hge;
00904     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00905     rpmds trigger = NULL;
00906     const char ** triggerScripts;
00907     const char ** triggerProgs;
00908     int_32 * triggerIndices;
00909     const char * sourceName;
00910     const char * triggerName;
00911     rpmRC rc = RPMRC_OK;
00912     int xx;
00913     int i;
00914 
00915     xx = headerNVR(sourceH, &sourceName, NULL, NULL);
00916     xx = headerNVR(triggeredH, &triggerName, NULL, NULL);
00917 
00918     trigger = rpmdsInit(rpmdsNew(triggeredH, RPMTAG_TRIGGERNAME, scareMem));
00919     if (trigger == NULL)
00920         return rc;
00921 
00922     (void) rpmdsSetNoPromote(trigger, 1);
00923 
00924     while ((i = rpmdsNext(trigger)) >= 0) {
00925         rpmTagType tit, tst, tpt;
00926         const char * Name;
00927         int_32 Flags = rpmdsFlags(trigger);
00928 
00929         if ((Name = rpmdsN(trigger)) == NULL)
00930             continue;   /* XXX can't happen */
00931 
00932         if (strcmp(Name, sourceName))
00933             continue;
00934         if (!(Flags & psm->sense))
00935             continue;
00936 
00937         /*
00938          * XXX Trigger on any provided dependency, not just the package NEVR.
00939          */
00940         if (!rpmdsAnyMatchesDep(sourceH, trigger, 1))
00941             continue;
00942 
00943         if (!(  hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit,
00944                        (void **) &triggerIndices, NULL) &&
00945                 hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst,
00946                        (void **) &triggerScripts, NULL) &&
00947                 hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt,
00948                        (void **) &triggerProgs, NULL))
00949             )
00950             continue;
00951 
00952         {   int arg1;
00953             int index;
00954 
00955             arg1 = rpmdbCountPackages(rpmtsGetRdb(ts), triggerName);
00956             if (arg1 < 0) {
00957                 /* XXX W2DO? fails as "execution of script failed" */
00958                 rc = RPMRC_FAIL;
00959             } else {
00960                 arg1 += psm->countCorrection;
00961                 index = triggerIndices[i];
00962                 if (triggersAlreadyRun == NULL ||
00963                     triggersAlreadyRun[index] == 0)
00964                 {
00965                     rc = runScript(psm, triggeredH, "%trigger", 1,
00966                             triggerProgs + index, triggerScripts[index], 
00967                             arg1, arg2);
00968                     if (triggersAlreadyRun != NULL)
00969                         triggersAlreadyRun[index] = 1;
00970                 }
00971             }
00972         }
00973 
00974         triggerIndices = hfd(triggerIndices, tit);
00975         triggerScripts = hfd(triggerScripts, tst);
00976         triggerProgs = hfd(triggerProgs, tpt);
00977 
00978         /*
00979          * Each target/source header pair can only result in a single
00980          * script being run.
00981          */
00982         break;
00983     }
00984 
00985     trigger = rpmdsFree(trigger);
00986 
00987     return rc;
00988 }
00989 
00995 static rpmRC runTriggers(rpmpsm psm)
00996         /*@globals rpmGlobalMacroContext, h_errno,
00997                 fileSystem, internalState @*/
00998         /*@modifies psm, rpmGlobalMacroContext,
00999                 fileSystem, internalState @*/
01000 {
01001     const rpmts ts = psm->ts;
01002     rpmfi fi = psm->fi;
01003     int numPackage = -1;
01004     rpmRC rc = RPMRC_OK;
01005     const char * N = NULL;
01006 
01007     if (psm->te)        /* XXX can't happen */
01008         N = rpmteN(psm->te);
01009     if (N)              /* XXX can't happen */
01010         numPackage = rpmdbCountPackages(rpmtsGetRdb(ts), N)
01011                                 + psm->countCorrection;
01012     if (numPackage < 0)
01013         return RPMRC_NOTFOUND;
01014 
01015     if (fi != NULL && fi->h != NULL)    /* XXX can't happen */
01016     {   Header triggeredH;
01017         rpmdbMatchIterator mi;
01018         int countCorrection = psm->countCorrection;
01019 
01020         psm->countCorrection = 0;
01021         mi = rpmtsInitIterator(ts, RPMTAG_TRIGGERNAME, N, 0);
01022         while((triggeredH = rpmdbNextIterator(mi)) != NULL)
01023             rc |= handleOneTrigger(psm, fi->h, triggeredH, numPackage, NULL);
01024         mi = rpmdbFreeIterator(mi);
01025         psm->countCorrection = countCorrection;
01026     }
01027 
01028     return rc;
01029 }
01030 
01036 static rpmRC runImmedTriggers(rpmpsm psm)
01037         /*@globals rpmGlobalMacroContext, h_errno,
01038                 fileSystem, internalState @*/
01039         /*@modifies psm, rpmGlobalMacroContext,
01040                 fileSystem, internalState @*/
01041 {
01042     const rpmts ts = psm->ts;
01043     rpmfi fi = psm->fi;
01044     HGE_t hge = fi->hge;
01045     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
01046     const char ** triggerNames;
01047     int numTriggers;
01048     int_32 * triggerIndices;
01049     rpmTagType tnt, tit;
01050     int numTriggerIndices;
01051     unsigned char * triggersRun;
01052     rpmRC rc = RPMRC_OK;
01053 
01054     if (fi->h == NULL)  return rc;      /* XXX can't happen */
01055 
01056     if (!(      hge(fi->h, RPMTAG_TRIGGERNAME, &tnt,
01057                         (void **) &triggerNames, &numTriggers) &&
01058                 hge(fi->h, RPMTAG_TRIGGERINDEX, &tit,
01059                         (void **) &triggerIndices, &numTriggerIndices))
01060         )
01061         return rc;
01062 
01063     triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
01064     memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
01065 
01066     {   Header sourceH = NULL;
01067         int i;
01068 
01069         for (i = 0; i < numTriggers; i++) {
01070             rpmdbMatchIterator mi;
01071 
01072             if (triggersRun[triggerIndices[i]] != 0) continue;
01073         
01074             mi = rpmtsInitIterator(ts, RPMTAG_NAME, triggerNames[i], 0);
01075 
01076             while((sourceH = rpmdbNextIterator(mi)) != NULL) {
01077                 rc |= handleOneTrigger(psm, sourceH, fi->h, 
01078                                 rpmdbGetIteratorCount(mi),
01079                                 triggersRun);
01080             }
01081 
01082             mi = rpmdbFreeIterator(mi);
01083         }
01084     }
01085     triggerIndices = hfd(triggerIndices, tit);
01086     triggerNames = hfd(triggerNames, tnt);
01087     return rc;
01088 }
01089 
01090 /*@observer@*/ static const char *const pkgStageString(pkgStage a)
01091         /*@*/
01092 {
01093     switch(a) {
01094     case PSM_UNKNOWN:           return "unknown";
01095 
01096     case PSM_PKGINSTALL:        return "  install";
01097     case PSM_PKGERASE:          return "    erase";
01098     case PSM_PKGCOMMIT:         return "   commit";
01099     case PSM_PKGSAVE:           return "repackage";
01100 
01101     case PSM_INIT:              return "init";
01102     case PSM_PRE:               return "pre";
01103     case PSM_PROCESS:           return "process";
01104     case PSM_POST:              return "post";
01105     case PSM_UNDO:              return "undo";
01106     case PSM_FINI:              return "fini";
01107 
01108     case PSM_CREATE:            return "create";
01109     case PSM_NOTIFY:            return "notify";
01110     case PSM_DESTROY:           return "destroy";
01111     case PSM_COMMIT:            return "commit";
01112 
01113     case PSM_CHROOT_IN:         return "chrootin";
01114     case PSM_CHROOT_OUT:        return "chrootout";
01115     case PSM_SCRIPT:            return "script";
01116     case PSM_TRIGGERS:          return "triggers";
01117     case PSM_IMMED_TRIGGERS:    return "immedtriggers";
01118 
01119     case PSM_RPMIO_FLAGS:       return "rpmioflags";
01120 
01121     case PSM_RPMDB_LOAD:        return "rpmdbload";
01122     case PSM_RPMDB_ADD:         return "rpmdbadd";
01123     case PSM_RPMDB_REMOVE:      return "rpmdbremove";
01124 
01125     default:                    return "???";
01126     }
01127     /*@noteached@*/
01128 }
01129 
01130 rpmpsm XrpmpsmUnlink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
01131 {
01132     if (psm == NULL) return NULL;
01133 /*@-modfilesys@*/
01134 if (_psm_debug && msg != NULL)
01135 fprintf(stderr, "--> psm %p -- %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
01136 /*@=modfilesys@*/
01137     psm->nrefs--;
01138     return NULL;
01139 }
01140 
01141 rpmpsm XrpmpsmLink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
01142 {
01143     if (psm == NULL) return NULL;
01144     psm->nrefs++;
01145 
01146 /*@-modfilesys@*/
01147 if (_psm_debug && msg != NULL)
01148 fprintf(stderr, "--> psm %p ++ %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
01149 /*@=modfilesys@*/
01150 
01151     /*@-refcounttrans@*/ return psm; /*@=refcounttrans@*/
01152 }
01153 
01154 rpmpsm rpmpsmFree(rpmpsm psm)
01155 {
01156     const char * msg = "rpmpsmFree";
01157     if (psm == NULL)
01158         return NULL;
01159 
01160     if (psm->nrefs > 1)
01161         return rpmpsmUnlink(psm, msg);
01162 
01163 /*@-nullstate@*/
01164     psm->fi = rpmfiFree(psm->fi);
01165 #ifdef  NOTYET
01166     psm->te = rpmteFree(psm->te);
01167 #else
01168     psm->te = NULL;
01169 #endif
01170 /*@-internalglobs@*/
01171     psm->ts = rpmtsFree(psm->ts);
01172 /*@=internalglobs@*/
01173 
01174     (void) rpmpsmUnlink(psm, msg);
01175 
01176     /*@-refcounttrans -usereleased@*/
01177 /*@-boundswrite@*/
01178     memset(psm, 0, sizeof(*psm));               /* XXX trash and burn */
01179 /*@=boundswrite@*/
01180     psm = _free(psm);
01181     /*@=refcounttrans =usereleased@*/
01182 
01183     return NULL;
01184 /*@=nullstate@*/
01185 }
01186 
01187 rpmpsm rpmpsmNew(rpmts ts, rpmte te, rpmfi fi)
01188 {
01189     const char * msg = "rpmpsmNew";
01190     rpmpsm psm = xcalloc(1, sizeof(*psm));
01191 
01192     if (ts)     psm->ts = rpmtsLink(ts, msg);
01193 #ifdef  NOTYET
01194     if (te)     psm->te = rpmteLink(te, msg);
01195 #else
01196 /*@-assignexpose -temptrans @*/
01197     if (te)     psm->te = te;
01198 /*@=assignexpose =temptrans @*/
01199 #endif
01200     if (fi)     psm->fi = rpmfiLink(fi, msg);
01201 
01202     return rpmpsmLink(psm, msg);
01203 }
01204 
01205 static void * rpmpsmThread(void * arg)
01206         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
01207         /*@modifies arg, rpmGlobalMacroContext, fileSystem, internalState @*/
01208 {
01209     rpmpsm psm = arg;
01210 /*@-unqualifiedtrans@*/
01211     return ((void *) rpmpsmStage(psm, psm->nstage));
01212 /*@=unqualifiedtrans@*/
01213 }
01214 
01215 static int rpmpsmNext(rpmpsm psm, pkgStage nstage)
01216         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
01217         /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
01218 {
01219     psm->nstage = nstage;
01220     if (_psm_threads)
01221         return rpmsqJoin( rpmsqThread(rpmpsmThread, psm) );
01222     return rpmpsmStage(psm, psm->nstage);
01223 }
01224 
01229 /*@-bounds -nullpass@*/ /* FIX: testing null annotation for fi->h */
01230 rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
01231 {
01232     const rpmts ts = psm->ts;
01233     uint_32 tscolor = rpmtsColor(ts);
01234     rpmfi fi = psm->fi;
01235     HGE_t hge = fi->hge;
01236     HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
01237     rpmRC rc = psm->rc;
01238     int saveerrno;
01239     int xx;
01240 
01241     /*@-branchstate@*/
01242     switch (stage) {
01243     case PSM_UNKNOWN:
01244         break;
01245     case PSM_INIT:
01246         rpmMessage(RPMMESS_DEBUG, _("%s: %s has %d files, test = %d\n"),
01247                 psm->stepName, rpmteNEVR(psm->te),
01248                 rpmfiFC(fi), (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST));
01249 
01250         /*
01251          * When we run scripts, we pass an argument which is the number of 
01252          * versions of this package that will be installed when we are
01253          * finished.
01254          */
01255         psm->npkgs_installed = rpmdbCountPackages(rpmtsGetRdb(ts), rpmteN(psm->te));
01256         if (psm->npkgs_installed < 0) {
01257             rc = RPMRC_FAIL;
01258             break;
01259         }
01260 
01261         if (psm->goal == PSM_PKGINSTALL) {
01262             int fc = rpmfiFC(fi);
01263 
01264             psm->scriptArg = psm->npkgs_installed + 1;
01265 
01266 assert(psm->mi == NULL);
01267             psm->mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(psm->te), 0);
01268             xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_EPOCH, RPMMIRE_STRCMP,
01269                         rpmteE(psm->te));
01270             xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_VERSION, RPMMIRE_STRCMP,
01271                         rpmteV(psm->te));
01272             xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_RELEASE, RPMMIRE_STRCMP,
01273                         rpmteR(psm->te));
01274             if (tscolor) {
01275                 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_ARCH, RPMMIRE_STRCMP,
01276                         rpmteA(psm->te));
01277                 xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_OS, RPMMIRE_STRCMP,
01278                         rpmteO(psm->te));
01279             }
01280 
01281             while ((psm->oh = rpmdbNextIterator(psm->mi)) != NULL) {
01282                 fi->record = rpmdbGetIteratorOffset(psm->mi);
01283                 psm->oh = NULL;
01284                 /*@loopbreak@*/ break;
01285             }
01286             psm->mi = rpmdbFreeIterator(psm->mi);
01287             rc = RPMRC_OK;
01288 
01289             /* XXX lazy alloc here may need to be done elsewhere. */
01290             if (fi->fstates == NULL && fc > 0) {
01291                 fi->fstates = xmalloc(sizeof(*fi->fstates) * fc);
01292                 memset(fi->fstates, RPMFILE_STATE_NORMAL, fc);
01293             }
01294 
01295             if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)  break;
01296             if (fc <= 0)                                break;
01297         
01298             /*
01299              * Old format relocatable packages need the entire default
01300              * prefix stripped to form the cpio list, while all other packages
01301              * need the leading / stripped.
01302              */
01303             {   const char * p;
01304                 xx = hge(fi->h, RPMTAG_DEFAULTPREFIX, NULL, (void **) &p, NULL);
01305                 fi->striplen = (xx ? strlen(p) + 1 : 1); 
01306             }
01307             fi->mapflags =
01308                 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
01309         
01310             if (headerIsEntry(fi->h, RPMTAG_ORIGBASENAMES))
01311                 rpmfiBuildFNames(fi->h, RPMTAG_ORIGBASENAMES, &fi->apath, NULL);
01312             else
01313                 rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
01314         
01315             if (fi->fuser == NULL)
01316                 xx = hge(fi->h, RPMTAG_FILEUSERNAME, NULL,
01317                                 (void **) &fi->fuser, NULL);
01318             if (fi->fgroup == NULL)
01319                 xx = hge(fi->h, RPMTAG_FILEGROUPNAME, NULL,
01320                                 (void **) &fi->fgroup, NULL);
01321             rc = RPMRC_OK;
01322         }
01323         if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
01324             psm->scriptArg = psm->npkgs_installed - 1;
01325         
01326             /* Retrieve installed header. */
01327             rc = rpmpsmNext(psm, PSM_RPMDB_LOAD);
01328 if (rc == RPMRC_OK)
01329 if (psm->te)
01330 psm->te->h = headerLink(fi->h);
01331         }
01332         if (psm->goal == PSM_PKGSAVE) {
01333             /* Open output package for writing. */
01334             {   const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL);
01335                 const char * pkgbn =
01336                         headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL);
01337 
01338                 bfmt = _free(bfmt);
01339                 psm->pkgURL = rpmGenPath("%{?_repackage_root}",
01340                                          "%{?_repackage_dir}",
01341                                         pkgbn);
01342                 pkgbn = _free(pkgbn);
01343                 (void) urlPath(psm->pkgURL, &psm->pkgfn);
01344                 psm->fd = Fopen(psm->pkgfn, "w.ufdio");
01345                 if (psm->fd == NULL || Ferror(psm->fd)) {
01346                     rc = RPMRC_FAIL;
01347                     break;
01348                 }
01349             }
01350         }
01351         break;
01352     case PSM_PRE:
01353         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01354 
01355 /* XXX insure that trigger index is opened before entering chroot. */
01356 #ifdef  NOTYET
01357  { static int oneshot = 0;
01358    dbiIndex dbi;
01359    if (!oneshot) {
01360      dbi = dbiOpen(rpmtsGetRdb(ts), RPMTAG_TRIGGERNAME, 0);
01361      oneshot++;
01362    }
01363  }
01364 #endif
01365 
01366         /* Change root directory if requested and not already done. */
01367         rc = rpmpsmNext(psm, PSM_CHROOT_IN);
01368 
01369         if (psm->goal == PSM_PKGINSTALL) {
01370             psm->scriptTag = RPMTAG_PREIN;
01371             psm->progTag = RPMTAG_PREINPROG;
01372 
01373             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPREIN)) {
01374                 /* XXX FIXME: implement %triggerprein. */
01375             }
01376 
01377             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPRE)) {
01378                 rc = rpmpsmNext(psm, PSM_SCRIPT);
01379                 if (rc != RPMRC_OK) {
01380                     rpmError(RPMERR_SCRIPT,
01381                         _("%s: %s scriptlet failed (%d), skipping %s\n"),
01382                         psm->stepName, tag2sln(psm->scriptTag), rc,
01383                         rpmteNEVR(psm->te));
01384                     break;
01385                 }
01386             }
01387         }
01388 
01389         if (psm->goal == PSM_PKGERASE) {
01390             psm->scriptTag = RPMTAG_PREUN;
01391             psm->progTag = RPMTAG_PREUNPROG;
01392             psm->sense = RPMSENSE_TRIGGERUN;
01393             psm->countCorrection = -1;
01394 
01395             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERUN)) {
01396                 /* Run triggers in this package other package(s) set off. */
01397                 rc = rpmpsmNext(psm, PSM_IMMED_TRIGGERS);
01398                 if (rc) break;
01399 
01400                 /* Run triggers in other package(s) this package sets off. */
01401                 rc = rpmpsmNext(psm, PSM_TRIGGERS);
01402                 if (rc) break;
01403             }
01404 
01405             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPREUN))
01406                 rc = rpmpsmNext(psm, PSM_SCRIPT);
01407         }
01408         if (psm->goal == PSM_PKGSAVE) {
01409             int noArchiveSize = 0;
01410 
01411             /* Regenerate original header. */
01412             {   void * uh = NULL;
01413                 int_32 uht, uhc;
01414 
01415                 if (headerGetEntry(fi->h, RPMTAG_HEADERIMMUTABLE, &uht, &uh, &uhc)) {
01416                     psm->oh = headerCopyLoad(uh);
01417                     uh = hfd(uh, uht);
01418                 } else
01419                 if (headerGetEntry(fi->h, RPMTAG_HEADERIMAGE, &uht, &uh, &uhc))
01420                 {
01421                     HeaderIterator hi;
01422                     int_32 tag, type, count;
01423                     hPTR_t ptr;
01424                     Header oh;
01425 
01426                     /* Load the original header from the blob. */
01427                     oh = headerCopyLoad(uh);
01428 
01429                     /* XXX this is headerCopy w/o headerReload() */
01430                     psm->oh = headerNew();
01431 
01432                     /*@-branchstate@*/
01433                     for (hi = headerInitIterator(oh);
01434                         headerNextIterator(hi, &tag, &type, &ptr, &count);
01435                         ptr = headerFreeData((void *)ptr, type))
01436                     {
01437                         if (tag == RPMTAG_ARCHIVESIZE)
01438                             noArchiveSize = 1;
01439                         if (ptr) (void) headerAddEntry(psm->oh, tag, type, ptr, count);
01440                     }
01441                     hi = headerFreeIterator(hi);
01442                     /*@=branchstate@*/
01443 
01444                     oh = headerFree(oh);
01445                     uh = hfd(uh, uht);
01446                 } else
01447                     break;      /* XXX shouldn't ever happen */
01448             }
01449 
01450             /* Retrieve type of payload compression. */
01451             /*@-nullstate@*/    /* FIX: psm->oh may be NULL */
01452             rc = rpmpsmNext(psm, PSM_RPMIO_FLAGS);
01453             /*@=nullstate@*/
01454 
01455             /* Write the lead section into the package. */
01456             {   int archnum = -1;
01457                 int osnum = -1;
01458                 struct rpmlead lead;
01459 
01460 #ifndef DYING
01461                 rpmGetArchInfo(NULL, &archnum);
01462                 rpmGetOsInfo(NULL, &osnum);
01463 #endif
01464 
01465                 memset(&lead, 0, sizeof(lead));
01466                 /* XXX Set package version conditioned on noDirTokens. */
01467                 lead.major = 3;
01468                 lead.minor = 0;
01469                 lead.type = RPMLEAD_BINARY;
01470                 lead.archnum = archnum;
01471                 lead.osnum = osnum;
01472                 lead.signature_type = RPMSIGTYPE_HEADERSIG;
01473 
01474                 strncpy(lead.name, rpmteNEVR(psm->te), sizeof(lead.name));
01475 
01476                 rc = writeLead(psm->fd, &lead);
01477                 if (rc != RPMRC_OK) {
01478                     rpmError(RPMERR_NOSPACE, _("Unable to write package: %s\n"),
01479                          Fstrerror(psm->fd));
01480                     break;
01481                 }
01482             }
01483 
01484             /* Write the signature section into the package. */
01485             /* XXX rpm-4.1 and later has archive size in signature header. */
01486             {   Header sigh = headerRegenSigHeader(fi->h, noArchiveSize);
01487                 /* Reallocate the signature into one contiguous region. */
01488                 sigh = headerReload(sigh, RPMTAG_HEADERSIGNATURES);
01489                 if (sigh == NULL) {
01490                     rpmError(RPMERR_NOSPACE, _("Unable to reload signature header\n"));
01491                     rc = RPMRC_FAIL;
01492                     break;
01493                 }
01494                 rc = rpmWriteSignature(psm->fd, sigh);
01495                 sigh = rpmFreeSignature(sigh);
01496                 if (rc) break;
01497             }
01498 
01499             /* Add remove transaction id to header. */
01500             if (psm->oh != NULL)
01501             {   int_32 tid = rpmtsGetTid(ts);
01502                 xx = headerAddEntry(psm->oh, RPMTAG_REMOVETID,
01503                         RPM_INT32_TYPE, &tid, 1);
01504             }
01505 
01506             /* Write the metadata section into the package. */
01507             rc = headerWrite(psm->fd, psm->oh, HEADER_MAGIC_YES);
01508             if (rc) break;
01509         }
01510         break;
01511     case PSM_PROCESS:
01512         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01513 
01514         if (psm->goal == PSM_PKGINSTALL) {
01515 
01516             if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)  break;
01517 
01518             /* XXX Synthesize callbacks for packages with no files. */
01519             if (rpmfiFC(fi) <= 0) {
01520                 void * ptr;
01521                 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_START, 0, 100);
01522                 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, 100, 100);
01523                 break;
01524             }
01525 
01526             /* Retrieve type of payload compression. */
01527             rc = rpmpsmNext(psm, PSM_RPMIO_FLAGS);
01528 
01529             if (rpmteFd(fi->te) == NULL) {      /* XXX can't happen */
01530                 rc = RPMRC_FAIL;
01531                 break;
01532             }
01533 
01534             /*@-nullpass@*/     /* LCL: fi->fd != NULL here. */
01535             psm->cfd = Fdopen(fdDup(Fileno(rpmteFd(fi->te))), psm->rpmio_flags);
01536             /*@=nullpass@*/
01537             if (psm->cfd == NULL) {     /* XXX can't happen */
01538                 rc = RPMRC_FAIL;
01539                 break;
01540             }
01541 
01542             rc = fsmSetup(fi->fsm, FSM_PKGINSTALL, ts, fi,
01543                         psm->cfd, NULL, &psm->failedFile);
01544             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_UNCOMPRESS),
01545                         fdstat_op(psm->cfd, FDSTAT_READ));
01546             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
01547                         fdstat_op(psm->cfd, FDSTAT_DIGEST));
01548             xx = fsmTeardown(fi->fsm);
01549 
01550             saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
01551             xx = Fclose(psm->cfd);
01552             psm->cfd = NULL;
01553             /*@-mods@*/
01554             errno = saveerrno; /* XXX FIXME: Fclose with libio destroys errno */
01555             /*@=mods@*/
01556 
01557             if (!rc)
01558                 rc = rpmpsmNext(psm, PSM_COMMIT);
01559 
01560             /* XXX make sure progress is closed out */
01561             psm->what = RPMCALLBACK_INST_PROGRESS;
01562             psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
01563             psm->total = psm->amount;
01564             xx = rpmpsmNext(psm, PSM_NOTIFY);
01565 
01566             if (rc) {
01567                 rpmError(RPMERR_CPIO,
01568                         _("unpacking of archive failed%s%s: %s\n"),
01569                         (psm->failedFile != NULL ? _(" on file ") : ""),
01570                         (psm->failedFile != NULL ? psm->failedFile : ""),
01571                         cpioStrerror(rc));
01572                 rc = RPMRC_FAIL;
01573 
01574                 /* XXX notify callback on error. */
01575                 psm->what = RPMCALLBACK_UNPACK_ERROR;
01576                 psm->amount = 0;
01577                 psm->total = 0;
01578                 xx = rpmpsmNext(psm, PSM_NOTIFY);
01579 
01580                 break;
01581             }
01582         }
01583         if (psm->goal == PSM_PKGERASE) {
01584             int fc = rpmfiFC(fi);
01585 
01586             if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)  break;
01587             if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY)       break;
01588             if (fc <= 0)                                break;
01589 
01590             psm->what = RPMCALLBACK_UNINST_START;
01591             psm->amount = fc;           /* XXX W2DO? looks wrong. */
01592             psm->total = fc;
01593             xx = rpmpsmNext(psm, PSM_NOTIFY);
01594 
01595             rc = fsmSetup(fi->fsm, FSM_PKGERASE, ts, fi,
01596                         NULL, NULL, &psm->failedFile);
01597             xx = fsmTeardown(fi->fsm);
01598 
01599             psm->what = RPMCALLBACK_UNINST_STOP;
01600             psm->amount = 0;            /* XXX W2DO? looks wrong. */
01601             psm->total = fc;
01602             xx = rpmpsmNext(psm, PSM_NOTIFY);
01603 
01604         }
01605         if (psm->goal == PSM_PKGSAVE) {
01606             fileAction * actions = fi->actions;
01607             fileAction action = fi->action;
01608 
01609             fi->action = FA_COPYOUT;
01610             fi->actions = NULL;
01611 
01612             if (psm->fd == NULL) {      /* XXX can't happen */
01613                 rc = RPMRC_FAIL;
01614                 break;
01615             }
01616             /*@-nullpass@*/     /* FIX: fdDup mey return NULL. */
01617             xx = Fflush(psm->fd);
01618             psm->cfd = Fdopen(fdDup(Fileno(psm->fd)), psm->rpmio_flags);
01619             /*@=nullpass@*/
01620             if (psm->cfd == NULL) {     /* XXX can't happen */
01621                 rc = RPMRC_FAIL;
01622                 break;
01623             }
01624 
01625             rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, psm->cfd,
01626                         NULL, &psm->failedFile);
01627             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_COMPRESS),
01628                         fdstat_op(psm->cfd, FDSTAT_WRITE));
01629             (void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
01630                         fdstat_op(psm->cfd, FDSTAT_DIGEST));
01631             xx = fsmTeardown(fi->fsm);
01632 
01633             saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
01634             xx = Fclose(psm->cfd);
01635             psm->cfd = NULL;
01636             /*@-mods@*/
01637             errno = saveerrno;
01638             /*@=mods@*/
01639 
01640             /* XXX make sure progress is closed out */
01641             psm->what = RPMCALLBACK_INST_PROGRESS;
01642             psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
01643             psm->total = psm->amount;
01644             xx = rpmpsmNext(psm, PSM_NOTIFY);
01645 
01646             fi->action = action;
01647             fi->actions = actions;
01648         }
01649         break;
01650     case PSM_POST:
01651         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01652 
01653         if (psm->goal == PSM_PKGINSTALL) {
01654             int_32 installTime = (int_32) time(NULL);
01655             int fc = rpmfiFC(fi);
01656 
01657             if (fi->h == NULL) break;   /* XXX can't happen */
01658             if (fi->fstates != NULL && fc > 0)
01659                 xx = headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE,
01660                                 fi->fstates, fc);
01661 
01662             xx = headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
01663                                 &installTime, 1);
01664 
01665             xx = headerAddEntry(fi->h, RPMTAG_INSTALLCOLOR, RPM_INT32_TYPE,
01666                                 &tscolor, 1);
01667 
01668             /*
01669              * If this package has already been installed, remove it from
01670              * the database before adding the new one.
01671              */
01672             if (fi->record && !(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY)) {
01673                 rc = rpmpsmNext(psm, PSM_RPMDB_REMOVE);
01674                 if (rc) break;
01675             }
01676 
01677             rc = rpmpsmNext(psm, PSM_RPMDB_ADD);
01678             if (rc) break;
01679 
01680             psm->scriptTag = RPMTAG_POSTIN;
01681             psm->progTag = RPMTAG_POSTINPROG;
01682             psm->sense = RPMSENSE_TRIGGERIN;
01683             psm->countCorrection = 0;
01684 
01685             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOST)) {
01686                 rc = rpmpsmNext(psm, PSM_SCRIPT);
01687                 if (rc) break;
01688             }
01689             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERIN)) {
01690                 /* Run triggers in other package(s) this package sets off. */
01691                 rc = rpmpsmNext(psm, PSM_TRIGGERS);
01692                 if (rc) break;
01693 
01694                 /* Run triggers in this package other package(s) set off. */
01695                 rc = rpmpsmNext(psm, PSM_IMMED_TRIGGERS);
01696                 if (rc) break;
01697             }
01698 
01699             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
01700                 rc = markReplacedFiles(psm);
01701 
01702         }
01703         if (psm->goal == PSM_PKGERASE) {
01704 
01705             psm->scriptTag = RPMTAG_POSTUN;
01706             psm->progTag = RPMTAG_POSTUNPROG;
01707             psm->sense = RPMSENSE_TRIGGERPOSTUN;
01708             psm->countCorrection = -1;
01709 
01710             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOSTUN)) {
01711                 rc = rpmpsmNext(psm, PSM_SCRIPT);
01712                 /* XXX WTFO? postun failures don't cause erasure failure. */
01713             }
01714 
01715             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPOSTUN)) {
01716                 /* Run triggers in other package(s) this package sets off. */
01717                 rc = rpmpsmNext(psm, PSM_TRIGGERS);
01718                 if (rc) break;
01719             }
01720 
01721             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
01722                 rc = rpmpsmNext(psm, PSM_RPMDB_REMOVE);
01723         }
01724         if (psm->goal == PSM_PKGSAVE) {
01725         }
01726 
01727         /* Restore root directory if changed. */
01728         xx = rpmpsmNext(psm, PSM_CHROOT_OUT);
01729         break;
01730     case PSM_UNDO:
01731         break;
01732     case PSM_FINI:
01733         /* Restore root directory if changed. */
01734         xx = rpmpsmNext(psm, PSM_CHROOT_OUT);
01735 
01736         if (psm->fd != NULL) {
01737             saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
01738             xx = Fclose(psm->fd);
01739             psm->fd = NULL;
01740             /*@-mods@*/
01741             errno = saveerrno;
01742             /*@=mods@*/
01743         }
01744 
01745         if (psm->goal == PSM_PKGSAVE) {
01746             if (!rc && ts && ts->notify == NULL) {
01747                 rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"),
01748                         (psm->pkgURL ? psm->pkgURL : "???"));
01749             }
01750         }
01751 
01752         if (rc) {
01753             if (psm->failedFile)
01754                 rpmError(RPMERR_CPIO,
01755                         _("%s failed on file %s: %s\n"),
01756                         psm->stepName, psm->failedFile, cpioStrerror(rc));
01757             else
01758                 rpmError(RPMERR_CPIO, _("%s failed: %s\n"),
01759                         psm->stepName, cpioStrerror(rc));
01760 
01761             /* XXX notify callback on error. */
01762             psm->what = RPMCALLBACK_CPIO_ERROR;
01763             psm->amount = 0;
01764             psm->total = 0;
01765             /*@-nullstate@*/ /* FIX: psm->fd may be NULL. */
01766             xx = rpmpsmNext(psm, PSM_NOTIFY);
01767             /*@=nullstate@*/
01768         }
01769 
01770 /*@-branchstate@*/
01771         if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
01772 if (psm->te != NULL)
01773 if (psm->te->h != NULL)
01774 psm->te->h = headerFree(psm->te->h);
01775             if (fi->h != NULL)
01776                 fi->h = headerFree(fi->h);
01777         }
01778 /*@=branchstate@*/
01779         psm->oh = headerFree(psm->oh);
01780         psm->pkgURL = _free(psm->pkgURL);
01781         psm->rpmio_flags = _free(psm->rpmio_flags);
01782         psm->failedFile = _free(psm->failedFile);
01783 
01784         fi->fgroup = hfd(fi->fgroup, -1);
01785         fi->fuser = hfd(fi->fuser, -1);
01786         fi->apath = _free(fi->apath);
01787         fi->fstates = _free(fi->fstates);
01788         break;
01789 
01790     case PSM_PKGINSTALL:
01791     case PSM_PKGERASE:
01792     case PSM_PKGSAVE:
01793         psm->goal = stage;
01794         psm->rc = RPMRC_OK;
01795         psm->stepName = pkgStageString(stage);
01796 
01797         rc = rpmpsmNext(psm, PSM_INIT);
01798         if (!rc) rc = rpmpsmNext(psm, PSM_PRE);
01799         if (!rc) rc = rpmpsmNext(psm, PSM_PROCESS);
01800         if (!rc) rc = rpmpsmNext(psm, PSM_POST);
01801         xx = rpmpsmNext(psm, PSM_FINI);
01802         break;
01803     case PSM_PKGCOMMIT:
01804         break;
01805 
01806     case PSM_CREATE:
01807         break;
01808     case PSM_NOTIFY:
01809     {   void * ptr;
01810 /*@-nullpass@*/ /* FIX: psm->te may be NULL */
01811         ptr = rpmtsNotify(ts, psm->te, psm->what, psm->amount, psm->total);
01812 /*@-nullpass@*/
01813     }   break;
01814     case PSM_DESTROY:
01815         break;
01816     case PSM_COMMIT:
01817         if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_PKGCOMMIT)) break;
01818         if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY) break;
01819 
01820         rc = fsmSetup(fi->fsm, FSM_PKGCOMMIT, ts, fi,
01821                         NULL, NULL, &psm->failedFile);
01822         xx = fsmTeardown(fi->fsm);
01823         break;
01824 
01825     case PSM_CHROOT_IN:
01826     {   const char * rootDir = rpmtsRootDir(ts);
01827         /* Change root directory if requested and not already done. */
01828         if (rootDir != NULL && !(rootDir[0] == '/' && rootDir[1] == '\0')
01829          && !rpmtsChrootDone(ts) && !psm->chrootDone)
01830         {
01831             static int _pw_loaded = 0;
01832             static int _gr_loaded = 0;
01833 
01834             if (!_pw_loaded) {
01835                 (void)getpwnam("root");
01836                 endpwent();
01837                 _pw_loaded++;
01838             }
01839             if (!_gr_loaded) {
01840                 (void)getgrnam("root");
01841                 endgrent();
01842                 _gr_loaded++;
01843             }
01844 
01845             xx = chdir("/");
01846             /*@-superuser@*/
01847             rc = chroot(rootDir);
01848             /*@=superuser@*/
01849             psm->chrootDone = 1;
01850             (void) rpmtsSetChrootDone(ts, 1);
01851         }
01852     }   break;
01853     case PSM_CHROOT_OUT:
01854         /* Restore root directory if changed. */
01855         if (psm->chrootDone) {
01856             const char * currDir = rpmtsCurrDir(ts);
01857             /*@-superuser@*/
01858             rc = chroot(".");
01859             /*@=superuser@*/
01860             psm->chrootDone = 0;
01861             (void) rpmtsSetChrootDone(ts, 0);
01862             if (currDir != NULL)        /* XXX can't happen */
01863                 xx = chdir(currDir);
01864         }
01865         break;
01866     case PSM_SCRIPT:    /* Run current package scriptlets. */
01867         rc = runInstScript(psm);
01868         break;
01869     case PSM_TRIGGERS:
01870         /* Run triggers in other package(s) this package sets off. */
01871         rc = runTriggers(psm);
01872         break;
01873     case PSM_IMMED_TRIGGERS:
01874         /* Run triggers in this package other package(s) set off. */
01875         rc = runImmedTriggers(psm);
01876         break;
01877 
01878     case PSM_RPMIO_FLAGS:
01879     {   const char * payload_compressor = NULL;
01880         char * t;
01881 
01882         /*@-branchstate@*/
01883         if (!hge(fi->h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
01884                             (void **) &payload_compressor, NULL))
01885             payload_compressor = "gzip";
01886         /*@=branchstate@*/
01887         psm->rpmio_flags = t = xmalloc(sizeof("w9.gzdio"));
01888         *t = '\0';
01889         t = stpcpy(t, ((psm->goal == PSM_PKGSAVE) ? "w9" : "r"));
01890         if (!strcmp(payload_compressor, "gzip"))
01891             t = stpcpy(t, ".gzdio");
01892         if (!strcmp(payload_compressor, "bzip2"))
01893             t = stpcpy(t, ".bzdio");
01894         rc = RPMRC_OK;
01895     }   break;
01896 
01897     case PSM_RPMDB_LOAD:
01898 assert(psm->mi == NULL);
01899         psm->mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
01900                                 &fi->record, sizeof(fi->record));
01901 
01902         fi->h = rpmdbNextIterator(psm->mi);
01903         if (fi->h != NULL)
01904             fi->h = headerLink(fi->h);
01905 
01906         psm->mi = rpmdbFreeIterator(psm->mi);
01907         rc = (fi->h != NULL ? RPMRC_OK : RPMRC_FAIL);
01908         break;
01909     case PSM_RPMDB_ADD:
01910         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01911         if (fi->h == NULL)      break;  /* XXX can't happen */
01912         (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
01913         if (!(rpmtsVSFlags(ts) & RPMVSF_NOHDRCHK))
01914             rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
01915                                 ts, headerCheck);
01916         else
01917             rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
01918                                 NULL, NULL);
01919         (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
01920         break;
01921     case PSM_RPMDB_REMOVE:
01922         if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)        break;
01923         (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
01924         rc = rpmdbRemove(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->record,
01925                                 NULL, NULL);
01926         (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
01927         break;
01928 
01929     default:
01930         break;
01931 /*@i@*/    }
01932     /*@=branchstate@*/
01933 
01934     /*@-nullstate@*/    /* FIX: psm->oh and psm->fi->h may be NULL. */
01935     return rc;
01936     /*@=nullstate@*/
01937 }
01938 /*@=bounds =nullpass@*/

Generated on Mon Jun 13 13:40:00 2005 for rpm by  doxygen 1.3.9.1