# lib/psm.c File Reference

Package state machine to handle a package from a transaction set. More...

`#include "system.h"`
`#include "psm.h"`
`#include <rpmmacro.h>`
`#include <rpmurl.h>`
`#include "depends.h"`
`#include "rpmlead.h"`
`#include "signature.h"`
`#include "ugid.h"`
`#include "misc.h"`
`#include "rpmdb.h"`
`#include "debug.h"`

Go to the source code of this file.

## Data Structures

struct | tagMacro
| Macros to be defined from per-header tag values. More...

## Functions

int | rpmVersionCompare (Header first, Header second)
| Compare headers to determine which header is "newer".
void | loadFi (Header h, TFI_t fi)
| Load data from header into transaction file element info.
void | freeFi (TFI_t fi)
| Destroy transaction element file info.
const char *const | fiTypeString (TFI_t fi)
| Return formatted string representation of package disposition.
static int | rpmInstallLoadMacros (TFI_t fi, Header h)
| Define per-header macros.
static int | mergeFiles (TFI_t fi, Header h, Header newH)
| Copy file data from h to newH.
static int | markReplacedFiles (PSM_t psm)
| Mark files in database shared with this package as "replaced".
static rpmRC | chkdir (const char *dpath, const char *dname)
| Create directory if it does not exist, make sure path is writable.
rpmRC | rpmInstallSourcePackage (const char *rootDir, FD_t fd, const char **specFilePtr, rpmCallbackFunction notify, rpmCallbackData notifyData, char **cookie)
| Install source package.
static const char *const | tag2sln (int tag)
| Return scriptlet name from tag.
static int | runScript (PSM_t psm, Header h, const char *sln, int progArgc, const char **progArgv, const char *script, int arg1, int arg2)
| Run scriptlet with args.
static rpmRC | runInstScript (PSM_t psm)
| Retrieve and run scriptlet from header.
static int | handleOneTrigger (PSM_t psm, Header sourceH, Header triggeredH, int arg2, unsigned char *triggersAlreadyRun)
static int | runTriggers (PSM_t psm)
| Run trigger scripts in the database that are fired by this header.
static int | runImmedTriggers (PSM_t psm)
| Run triggers from this header that are fired by headers in the database.
static const char *const | pkgStageString (pkgStage a)
int | psmStage (PSM_t psm, pkgStage stage)
| Package state machine driver.

## Variables

static struct tagMacro | tagMacros []
| Macros to be defined from per-header tag values.
static char * | SCRIPT_PATH

## Detailed Description

Package state machine to handle a package from a transaction set.

Definition in file psm.c.

## Function Documentation

static rpmRC chkdir | ( | const char * | dpath,
|  | const char * | dname |
| ) |  |  | `[static]`

Create directory if it does not exist, make sure path is writable.

Note:
  This will only create last component of directory path.

Parameters:

  | dpath | directory path
  | dname | directory use

Returns:
  rpmRC return code

Definition at line 577 of file psm.c.

References _, Access(), errno, Mkdir(), RPMERR_CREATE, rpmError, RPMRC_FAIL, RPMRC_OK, Stat(), URL_IS_DASH, URL_IS_FTP, URL_IS_HTTP, URL_IS_PATH, URL_IS_UNKNOWN, urlPath(), and W_OK.

const char* const fiTypeString | ( | TFI_t | fi | ) |

Return formatted string representation of package disposition.

Parameters:

  | a | package dispostion

Returns:
  formatted string

Definition at line 235 of file psm.c.

References transactionFileInfo_s::type.

Referenced by fsmStage().

void freeFi | ( | TFI_t | fi | ) |

Destroy transaction element file info.

Parameters:

  | fi | transaction element file info

Definition at line 188 of file psm.c.

References _free(), transactionFileInfo_s::actions, transactionFileInfo_s::apath, transactionFileInfo_s::bnl, transactionFileInfo_s::dil, transactionFileInfo_s::dnl, transactionFileInfo_s::fflags, transactionFileInfo_s::fgids, transactionFileInfo_s::fgroup, transactionFileInfo_s::flangs, transactionFileInfo_s::flinks, transactionFileInfo_s::fmapflags, transactionFileInfo_s::fmd5s, transactionFileInfo_s::fmodes, freeFSM(), transactionFileInfo_s::fsizes, transactionFileInfo_s::fsm, transactionFileInfo_s::fstates, transactionFileInfo_s::fuids, transactionFileInfo_s::fuser, transactionFileInfo_s::h, headerFree(), headerFreeData(), transactionFileInfo_s::hfd, transactionFileInfo_s::name, transactionFileInfo_s::obnl, transactionFileInfo_s::odnl, transactionFileInfo_s::release, transactionFileInfo_s::replaced, transactionFileInfo_s::replacedSizes, transactionFileInfo_s::type, and transactionFileInfo_s::version.

Referenced by freeFl(), freePackage(), freeSpec(), and rpmVerifyScript().

static int handleOneTrigger | ( | PSM_t | psm,
|  | Header | sourceH,
|  | Header | triggeredH,
|  | int | arg2,
|  | unsigned char * | triggersAlreadyRun |
| ) |  |  | `[static]`

Parameters:

  | psm | package state machine data
  | sourceH |
  | triggeredH |
  | arg2 |
  | triggersAlreadyRun |

Returns:

Definition at line 1093 of file psm.c.

References psm_s::countCorrection, psm_s::fi, headerFreeData(), headerMatchesDepFlags(), headerNVR(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, psm_s::rc, rpmTransactionSet_s::rpmdb, rpmdbCountPackages(), RPMRC_FAIL, RPMRC_OK, RPMTAG_TRIGGERFLAGS, RPMTAG_TRIGGERINDEX, RPMTAG_TRIGGERNAME, RPMTAG_TRIGGERSCRIPTPROG, RPMTAG_TRIGGERSCRIPTS, RPMTAG_TRIGGERVERSION, runScript(), psm_s::sense, and psm_s::ts.

Referenced by runImmedTriggers(), and runTriggers().

void loadFi | ( | Header | h,
|  | TFI_t | fi |
| ) |  |  |

Load data from header into transaction file element info.

Parameters:

  | h | header
  | fi | transaction element file info

Definition at line 72 of file psm.c.

References transactionFileInfo_s::action, transactionFileInfo_s::actions, transactionFileInfo_s::archiveSize, transactionFileInfo_s::bnl, transactionFileInfo_s::bnlmax, CPIO_ALL_HARDLINKS, CPIO_MAP_ABSOLUTE, CPIO_MAP_ADDDOT, CPIO_MAP_GID, CPIO_MAP_MODE, CPIO_MAP_PATH, CPIO_MAP_UID, transactionFileInfo_s::dc, transactionFileInfo_s::dil, transactionFileInfo_s::dnl, transactionFileInfo_s::dnlmax, transactionFileInfo_s::dperms, transactionFileInfo_s::epoch, FA_UNKNOWN, transactionFileInfo_s::fc, transactionFileInfo_s::fflags, transactionFileInfo_s::flags, transactionFileInfo_s::flangs, transactionFileInfo_s::flinks, transactionFileInfo_s::fmd5s, transactionFileInfo_s::fmodes, transactionFileInfo_s::fmtimes, transactionFileInfo_s::fperms, transactionFileInfo_s::frdevs, transactionFileInfo_s::fsizes, transactionFileInfo_s::fsm, transactionFileInfo_s::fstates, transactionFileInfo_s::h, transactionFileInfo_s::hae, headerAddEntry(), headerFree(), headerFreeData(), headerGetEntry(), headerGetEntryMinMemory(), headerLink(), headerModifyEntry(), headerRemoveEntry(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, transactionFileInfo_s::hme, transactionFileInfo_s::hre, transactionFileInfo_s::mapflags, transactionFileInfo_s::name, newFSM(), transactionFileInfo_s::release, transactionFileInfo_s::replacedSizes, RPMTAG_ARCHIVESIZE, RPMTAG_BASENAMES, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, RPMTAG_EPOCH, RPMTAG_FILEFLAGS, RPMTAG_FILELANGS, RPMTAG_FILELINKTOS, RPMTAG_FILEMD5S, RPMTAG_FILEMODES, RPMTAG_FILEMTIMES, RPMTAG_FILERDEVS, RPMTAG_FILESIZES, RPMTAG_FILESTATES, RPMTAG_NAME, RPMTAG_RELEASE, RPMTAG_VERSION, transactionFileInfo_s::type, transactionFileInfo_s::version, xcalloc(), xmalloc(), and xstrdup().

Referenced by genCpioListAndHeader(), rpmInstallSourcePackage(), rpmRunTransactions(), and rpmVerifyScript().

static int markReplacedFiles | ( | PSM_t | psm | ) | `[static]`

Mark files in database shared with this package as "replaced".

Parameters:

  | psm | package state machine data

Returns:
  0 always

Definition at line 497 of file psm.c.

References alloca(), transactionFileInfo_s::fc, psm_s::fi, transactionFileInfo_s::hge, sharedFileInfo::otherPkg, transactionFileInfo_s::replaced, rpmTransactionSet_s::rpmdb, rpmdbAppendIterator(), rpmdbFreeIterator(), rpmdbGetIteratorOffset(), RPMDBI_PACKAGES, rpmdbInitIterator(), rpmdbNextIterator(), rpmdbSetIteratorModified(), rpmdbSetIteratorRewrite(), RPMFILE_STATE_REPLACED, RPMTAG_FILESTATES, and psm_s::ts.

static int mergeFiles | ( | TFI_t | fi,
|  | Header | h,
|  | Header | newH |
| ) |  |  | `[static]`

Copy file data from h to newH.

Parameters:

  | h | header from
  | newH | header to
  | actions | array of file dispositions

Returns:
  0 on success, 1 on failure

Definition at line 314 of file psm.c.

References _, transactionFileInfo_s::actions, FA_SKIPMULTILIB, headerAddOrAppendEntry(), headerFreeData(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, transactionFileInfo_s::hme, isDependsMULTILIB, RPM_CHAR_TYPE, RPM_INT16_TYPE, RPM_INT32_TYPE, RPM_INT8_TYPE, RPM_STRING_ARRAY_TYPE, RPMERR_DATATYPE, rpmError, RPMSENSE_SENSEMASK, RPMTAG_BASENAMES, RPMTAG_CONFLICTFLAGS, RPMTAG_CONFLICTNAME, RPMTAG_CONFLICTVERSION, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, RPMTAG_FILEDEVICES, RPMTAG_FILEFLAGS, RPMTAG_FILEGROUPNAME, RPMTAG_FILEINODES, RPMTAG_FILELANGS, RPMTAG_FILELINKTOS, RPMTAG_FILEMD5S, RPMTAG_FILEMODES, RPMTAG_FILEMTIMES, RPMTAG_FILERDEVS, RPMTAG_FILESIZES, RPMTAG_FILESTATES, RPMTAG_FILEUSERNAME, RPMTAG_FILEVERIFYFLAGS, RPMTAG_PROVIDEFLAGS, RPMTAG_PROVIDENAME, RPMTAG_PROVIDEVERSION, RPMTAG_REQUIREFLAGS, RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION, RPMTAG_SIZE, and xcalloc().

static const char* const pkgStageString | ( | pkgStage | a | ) | `[static]`

Definition at line 1298 of file psm.c.

References PSM_CHROOT_IN, PSM_CHROOT_OUT, PSM_COMMIT, PSM_CREATE, PSM_DESTROY, PSM_FINI, PSM_IMMED_TRIGGERS, PSM_INIT, PSM_NOTIFY, PSM_PKGCOMMIT, PSM_PKGERASE, PSM_PKGINSTALL, PSM_PKGSAVE, PSM_POST, PSM_PRE, PSM_PROCESS, PSM_RPMDB_ADD, PSM_RPMDB_LOAD, PSM_RPMDB_REMOVE, PSM_RPMIO_FLAGS, PSM_SCRIPT, PSM_TRIGGERS, PSM_UNDO, and PSM_UNKNOWN.

int psmStage | ( | PSM_t | psm,
|  | pkgStage | stage |
| ) |  |  |

Package state machine driver.

Todo:
  Packages w/o files never get a callback, hence don't get displayed on install with -v.

Definition at line 1342 of file psm.c.

References _, _free(), psm_s::amount, transactionFileInfo_s::ap, transactionFileInfo_s::apath, transactionFileInfo_s::archiveSize, buildOrigFileList(), psm_s::cfd, psm_s::countCorrection, CPIO_MAP_GID, CPIO_MAP_MODE, CPIO_MAP_PATH, CPIO_MAP_UID, cpioStrerror(), errno, psm_s::failedFile, transactionFileInfo_s::fc, Fclose(), psm_s::fd, fdDup(), Fdopen(), Ferror(), transactionFileInfo_s::fgids, transactionFileInfo_s::fgroup, psm_s::fi, Fileno(), transactionFileInfo_s::fmodes, Fopen(), transactionFileInfo_s::fsm, FSM_PKGINSTALL, fsmSetup(), fsmTeardown(), transactionFileInfo_s::fstates, Fstrerror(), transactionFileInfo_s::fuids, transactionFileInfo_s::fuser, transactionFileInfo_s::gid, gnameToGid(), psm_s::goal, transactionFileInfo_s::h, HEADER_MAGIC_YES, headerAddEntry(), headerCopy(), headerCopyLoad(), headerFree(), headerFreeData(), headerFreeIterator(), headerGetEntry(), headerInitIterator(), headerIsEntry(), headerNew(), headerNextIterator(), headerRegenSigHeader(), headerSprintf(), headerWrite(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, transactionFileInfo_s::hme, rpmTransactionSet_s::id, transactionFileInfo_s::mapflags, psm_s::mi, transactionFileInfo_s::name, psm_s::npkgs_installed, psm_s::oh, psm_s::pkgfn, psm_s::pkgURL, psm_s::progTag, PSM_CHROOT_IN, PSM_COMMIT, PSM_IMMED_TRIGGERS, PSM_INIT, PSM_NOTIFY, PSM_PKGERASE, PSM_PKGINSTALL, PSM_PKGSAVE, PSM_PRE, PSM_PROCESS, PSM_RPMDB_LOAD, PSM_RPMIO_FLAGS, PSM_SCRIPT, PSM_TRIGGERS, PSM_UNKNOWN, psmStage(), psm_s::rc, transactionFileInfo_s::record, transactionFileInfo_s::release, RPM_INT32_TYPE, rpmBuildFileList(), RPMCALLBACK_INST_PROGRESS, rpmTransactionSet_s::rpmdb, rpmdbCountPackages(), rpmdbFreeIterator(), rpmdbGetIteratorOffset(), rpmdbInitIterator(), rpmdbNextIterator(), rpmdbSetIteratorRE(), RPMERR_CPIO, RPMERR_NOSPACE, RPMERR_SCRIPT, rpmError, RPMFILE_STATE_NORMAL, rpmFreeSignature(), rpmGenPath(), rpmGetArchInfo(), rpmGetOsInfo(), rpmGetPath(), rpmHeaderFormats, psm_s::rpmio_flags, RPMLEAD_BINARY, RPMMESS_DEBUG, RPMMESS_WARNING, rpmMessage, RPMMIRE_DEFAULT, RPMRC_FAIL, RPMRC_OK, RPMSENSE_TRIGGERUN, RPMSIGTYPE_HEADERSIG, RPMTAG_DEFAULTPREFIX, RPMTAG_FILEGROUPNAME, RPMTAG_FILEUSERNAME, RPMTAG_HEADERIMAGE, RPMTAG_HEADERIMMUTABLE, RPMTAG_NAME, RPMTAG_ORIGBASENAMES, RPMTAG_PREIN, RPMTAG_PREINPROG, RPMTAG_PREUN, RPMTAG_PREUNPROG, RPMTAG_RELEASE, RPMTAG_REMOVETID, RPMTAG_VERSION, rpmTagTable, RPMTRANS_FLAG_JUSTDB, RPMTRANS_FLAG_MULTILIB, RPMTRANS_FLAG_NOPRE, RPMTRANS_FLAG_NOPREUN, RPMTRANS_FLAG_NOTRIGGERPREIN, RPMTRANS_FLAG_NOTRIGGERUN, RPMTRANS_FLAG_TEST, rpmWriteSignature(), psm_s::scriptArg, psm_s::scriptTag, psm_s::sense, psm_s::stepName, transactionFileInfo_s::striplen, tag2sln(), psm_s::total, rpmTransactionSet_s::transFlags, psm_s::ts, transactionFileInfo_s::uid, unameToUid(), urlPath(), transactionFileInfo_s::version, psm_s::what, writeLead(), xcalloc(), and xmalloc().

Referenced by psmStage(), and rpmVerifyScript().

static int rpmInstallLoadMacros | ( | TFI_t | fi,
|  | Header | h |
| ) |  |  | `[static]`

Define per-header macros.

Parameters:

  | fi | transaction element file info
  | h | header

Returns:
  0 always

Definition at line 267 of file psm.c.

References transactionFileInfo_s::hge.

Referenced by rpmInstallSourcePackage().

rpmRC rpmInstallSourcePackage | ( | const char * | rootDir,
|  | FD_t | fd,
|  | const char ** | specFilePtr,
|  | rpmCallbackFunction | notify,
|  | rpmCallbackData | notifyData,
|  | char ** | cookie |
| ) |  |  |

Install source package.

Parameters:

  | rootDir | path to top of install tree (or NULL)
  | fd | file handle

Return values:

  | specFilePtr | address of spec file name (or NULL)

Parameters:

  | notify | progress callback
  | notifyData | progress callback private data

Return values:

  | cooke | address of cookie pointer (or NULL)

Returns:
  rpmRC return code

Definition at line 612 of file psm.c.

References _, _free(), rpmTransactionSet_s::addedPackages, CPIO_MAP_GID, CPIO_MAP_MODE, CPIO_MAP_PATH, CPIO_MAP_UID, FA_CREATE, psm_s::fd, headerFree(), headerFreeData(), headerIsEntry(), availableList_s::list, loadFi(), rpmTransactionSet_s::notify, rpmTransactionSet_s::notifyData, psm_s::rc, rpmBuildFileList(), RPMERR_NOTSRPM, rpmError, RPMFILE_SPECFILE, rpmInstallLoadMacros(), RPMRC_FAIL, rpmReadPackageHeader(), RPMTAG_COOKIE, rpmtransAddPackage(), rpmtransCreateSet(), psm_s::ts, xcalloc(), and xstrdup().

Referenced by rpmInstall(), and rpmInstallSource().

int rpmVersionCompare | ( | Header | first,
|  | Header | second |
| ) |  |  |

Compare headers to determine which header is "newer".

Parameters:

  | first | 1st header
  | second | 2nd header

Returns:
  result of comparison

Definition at line 36 of file psm.c.

References headerGetEntry(), RPMTAG_EPOCH, RPMTAG_RELEASE, RPMTAG_VERSION, and rpmvercmp().

Referenced by alAddPackage(), ensureOlder(), findUpgradePackages(), pkgCompareVer(), rpmInstall(), rpmtransAddPackage(), unmarkPackagesAlreadyInstalled(), and versionCompare().

static int runImmedTriggers | ( | PSM_t | psm | ) | `[static]`

Run triggers from this header that are fired by headers in the database.

Parameters:

  | psm | package state machine data

Returns:
  0 on success, 1 on error

Definition at line 1246 of file psm.c.

References alloca(), psm_s::fi, transactionFileInfo_s::h, handleOneTrigger(), headerFreeData(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, psm_s::mi, psm_s::rc, rpmTransactionSet_s::rpmdb, rpmdbFreeIterator(), rpmdbGetIteratorCount(), rpmdbInitIterator(), rpmdbNextIterator(), RPMRC_OK, RPMTAG_NAME, RPMTAG_TRIGGERINDEX, RPMTAG_TRIGGERNAME, and psm_s::ts.

static rpmRC runInstScript | ( | PSM_t | psm | ) | `[static]`

Retrieve and run scriptlet from header.

Parameters:

  | psm | package state machine data

Returns:
  rpmRC return code

Definition at line 1046 of file psm.c.

References alloca(), psm_s::fi, transactionFileInfo_s::h, headerFreeData(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, psm_s::progTag, psm_s::rc, RPM_STRING_TYPE, RPMRC_OK, runScript(), psm_s::scriptArg, psm_s::scriptTag, and tag2sln().

static int runScript | ( | PSM_t | psm,
|  | Header | h,
|  | const char * | sln,
|  | int | progArgc,
|  | const char ** | progArgv,
|  | const char * | script,
|  | int | arg1,
|  | int | arg2 |
| ) |  |  | `[static]`

Run scriptlet with args.

Run a script with an interpreter. If the interpreter is not specified, /bin/sh will be used. If the interpreter is /bin/sh, then the args from the header will be ignored, passing instead arg1 and arg2.

Parameters:

  | psm | package state machine data
  | h | header
  | sln | name of scriptlet section
  | progArgc | no. of args from header
  | progArgv | args from header, progArgv[0] is the interpreter to use
  | script | scriptlet from header
  | arg1 | no. instances of package installed after scriptlet exec (-1 is no arg)
  | arg2 | ditto, but for the target package

Returns:
  0 on success, 1 on error

Definition at line 825 of file psm.c.

References _, _free(), alloca(), rpmTransactionSet_s::chrootDone, doputenv(), errno, Fclose(), psm_s::fd, fdDup(), fdLink, Ferror(), psm_s::fi, Fileno(), Fopen(), Fwrite(), headerFreeData(), headerNVR(), transactionFileInfo_s::hfd, transactionFileInfo_s::hge, makeTempFile(), psm_s::rc, rpmTransactionSet_s::rootDir, RPMERR_SCRIPT, rpmError, rpmExpand(), rpmIsDebug, rpmIsVerbose, RPMRC_FAIL, RPMRC_OK, RPMTAG_INSTALLPREFIX, RPMTAG_INSTPREFIXES, rpmTransactionSet_s::scriptFd, strerror(), psm_s::ts, URL_IS_PATH, URL_IS_UNKNOWN, and urlIsURL().

Referenced by handleOneTrigger(), and runInstScript().

static int runTriggers | ( | PSM_t | psm | ) | `[static]`

Run trigger scripts in the database that are fired by this header.

Parameters:

  | psm | package state machine data

Returns:
  0 on success, 1 on error

Definition at line 1209 of file psm.c.

References psm_s::countCorrection, psm_s::fi, transactionFileInfo_s::h, handleOneTrigger(), psm_s::mi, transactionFileInfo_s::name, psm_s::rc, rpmTransactionSet_s::rpmdb, rpmdbCountPackages(), rpmdbFreeIterator(), rpmdbInitIterator(), rpmdbNextIterator(), RPMRC_OK, RPMTAG_TRIGGERNAME, and psm_s::ts.

static const char* const tag2sln | ( | int | tag | ) | `[static]`

Return scriptlet name from tag.

Parameters:

  | tag | scriptlet tag

Returns:
  name of scriptlet

Definition at line 794 of file psm.c.

References RPMTAG_POSTIN, RPMTAG_POSTUN, RPMTAG_PREIN, RPMTAG_PREUN, and RPMTAG_VERIFYSCRIPT.

Referenced by psmStage(), and runInstScript().

## Variable Documentation

char* SCRIPT_PATH`[static]`

Initial value:

            "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"

Definition at line 786 of file psm.c.

struct tagMacro tagMacros[]`[static]`

Macros to be defined from per-header tag values.

Todo:
  Should other macros be added from header when installing a package?