fsm.c File Reference
PAYLOAD.

File state machine to handle a payload from a package. More...

`#include "system.h"`
`#include <rpmio_internal.h>`
`#include <rpmcb.h>`
`#include <rpmtag.h>`
`#include <rpmtypes.h>`
`#include "rpmfi.h"`
`#include <fsm.h>`
`#include "cpio.h"`
`#include "tar.h"`
`#include "rpmte.h"`
`#include "rpmts.h"`
`#include "rpmsq.h"`
`#include "ugid.h"`
`#include "debug.h"`
Include dependency graph for fsm.c:

Go to the source code of this file.

## Data Structures

struct | dnli_s
| Directory name iterator. More...

## Macros

#define | _RPMFI_INTERNAL
#define | _IOSM_INTERNAL
#define | fsmUNSAFE fsmStage
#define | _USE_RPMTE
#define | alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
#define | _FSM_DEBUG 0
#define | SUFFIX_RPMORIG ".rpmorig"
#define | SUFFIX_RPMSAVE ".rpmsave"
#define | SUFFIX_RPMNEW ".rpmnew"
#define | _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
#define | IS_DEV_LOG(_x)
#define | _fafilter(_a)

## Typedefs

typedef struct dnli_s * | DNLI_t
| Directory name iterator. More...

## Functions

static rpmts | fsmGetTs (const IOSM_t fsm)
| Retrieve transaction set from file state machine iterator. More...
static rpmfi | fsmGetFi (const IOSM_t fsm)
| Retrieve transaction element file info from file state machine iterator. More...
static const char * | fsmFsPath (const IOSM_t fsm, const struct stat *st, const char *subdir, const char *suffix)
| Build path to file from file info, ornamented with subdir and suffix. More...
static void * | mapFreeIterator (void *p)
| Destroy file info iterator. More...
static void * | mapInitIterator (rpmfi fi, int reverse)
| Create file info iterator. More...
static int | mapNextIterator (void *a)
| Return next index into file info. More...
static int | cpioStrCmp (const void *a, const void *b)
static int | mapFind (FSMI_t iter, const char *fsmPath)
| Locate archive path in file info. More...
static void * | dnlFreeIterator (const void *a)
| Destroy directory name iterator. More...
static int | dnlCount (const DNLI_t dnli)
static int | dnlIndex (const DNLI_t dnli)
static void * | dnlInitIterator (const IOSM_t fsm, int reverse)
| Create directory name iterator. More...
static const char * | dnlNextIterator (DNLI_t dnli)
| Return next directory name (from file info). More...
int | fsmNext (IOSM_t fsm, iosmFileStage nstage)
| File state machine driver. More...
static int | saveHardLink (IOSM_t fsm)
| Save hard link in chain. More...
static void * | freeHardLink (struct hardLink_s *li)
| Destroy set of hard links. More...
IOSM_t | newFSM (void)
| Create file state machine instance. More...
IOSM_t | freeFSM (IOSM_t fsm)
| Destroy file state machine instance. More...
int | fsmSetup (void *_fsm, iosmFileStage goal, const char *afmt, const void *_ts, const void *_fi, FD_t cfd, unsigned int *archiveSize, const char **failedFile)
| Load external data into file state machine. More...
int | fsmTeardown (void *_fsm)
| Clean file state machine. More...
static int | fsmMapFContext (IOSM_t fsm)
int | fsmMapPath (IOSM_t fsm)
| Map next file path and action. More...
int | fsmMapAttrs (IOSM_t fsm)
| Map file stat(2) info. More...
static int | extractRegular (IOSM_t fsm)
| Create file from payload stream. More...
static int | writeFile (IOSM_t fsm, int writeData)
| Write next item to payload stream. More...
static int | writeLinkedFile (IOSM_t fsm)
| Write set of linked files to payload stream. More...
static int | fsmMakeLinks (IOSM_t fsm)
| Create pending hard links to existing file. More...
static int | fsmCommitLinks (IOSM_t fsm)
| Commit hard linked file set atomically. More...
static int | fsmRmdirs (IOSM_t fsm)
| Remove (if created) directories not explicitly included in package. More...
static int | fsmMkdirs (IOSM_t fsm)
| Create (if necessary) directories not explicitly included in package. More...
int | fsmStage (IOSM_t fsm, iosmFileStage stage)
| File state machine driver. More...

## Variables

int | _fsm_debug = 0
int | _fsm_threads = 0

## Detailed Description

File state machine to handle a payload from a package.

Definition in file fsm.c.

## Macro Definition Documentation

#define _fafilter | ( |  | _a | ) |

Value:
(!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
? iosmFileActionString(_a) : "")

Referenced by fsmStage(), and iosmStage().

#define _FSM_DEBUG 0

Definition at line 50 of file fsm.c.

#define _IOSM_INTERNAL

Definition at line 16 of file fsm.c.

#define _RPMFI_INTERNAL

Definition at line 13 of file fsm.c.

#define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)

Referenced by fsmSetup(), and iosmSetup().

#define _USE_RPMTE

Definition at line 26 of file fsm.c.

#define alloca_strdup | ( |  | _s | ) | strcpy(alloca(strlen(_s)+1), (_s))

Definition at line 48 of file fsm.c.

#define fsmUNSAFE fsmStage

Definition at line 18 of file fsm.c.

Referenced by fsmMakeLinks(), fsmMkdirs(), fsmSetup(), fsmStage(), fsmTeardown(), and writeFile().

#define IS_DEV_LOG | ( |  | _x | ) |

Value:
((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
!strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
((_x)[sizeof("/dev/log")-1] == '\0' || \
(_x)[sizeof("/dev/log")-1] == ';'))

Definition at line 1583 of file fsm.c.

Referenced by fsmStage().

#define SUFFIX_RPMNEW ".rpmnew"

Definition at line 89 of file fsm.c.

Referenced by fsmMapPath().

#define SUFFIX_RPMORIG ".rpmorig"

Definition at line 87 of file fsm.c.

Referenced by fsmMapPath().

#define SUFFIX_RPMSAVE ".rpmsave"

Definition at line 88 of file fsm.c.

Referenced by fsmMapPath().

## Function Documentation

IOSM_t freeFSM | ( | IOSM_t | fsm | ) |

Destroy file state machine instance.

Parameters

  fsm | file state machine

Returns
  always NULL

Definition at line 547 of file fsm.c.

References _free(), freeHardLink(), and mapFreeIterator().

Referenced by rpmfiFini().

static rpmfi fsmGetFi | ( | const IOSM_t | fsm | ) |

static

Retrieve transaction element file info from file state machine iterator.

Parameters

  fsm | file state machine

Returns
  transaction element file info

Definition at line 78 of file fsm.c.

Referenced by dnlInitIterator(), fsmMapAttrs(), fsmMapFContext(), fsmMapPath(), fsmMkdirs(), fsmStage(), saveHardLink(), and writeFile().

static rpmts fsmGetTs | ( | const IOSM_t | fsm | ) |

static

Retrieve transaction set from file state machine iterator.

Parameters

  fsm | file state machine

Returns
  transaction set

Definition at line 64 of file fsm.c.

Referenced by fsmStage(), and fsmTeardown().

int fsmMapAttrs | ( | IOSM_t | fsm | ) |

Map file stat(2) info.

Parameters

  fsm | file state machine

Definition at line 890 of file fsm.c.

References _, fsmGetFi(), gnameToGid(), IOSM_MAP_GID, IOSM_MAP_MODE, IOSM_MAP_TYPE, IOSM_MAP_UID, IOSM_PKGINSTALL, rpmlog(), RPMLOG_WARNING, and unameToUid().

Referenced by fsmStage().

static int fsmMapFContext | ( | IOSM_t | fsm | ) |

static

Definition at line 773 of file fsm.c.

References fsmGetFi(), and matchpathcon.

Referenced by fsmStage().

int fsmMapPath | ( | IOSM_t | fsm | ) |

Map next file path and action.

Parameters

  fsm | file state machine

Definition at line 799 of file fsm.c.

References _free(), FA_ALTNAME, FA_BACKUP, FA_COPYIN, FA_COPYOUT, FA_CREATE, FA_ERASE, FA_SAVE, FA_SKIP, FA_SKIPCOLOR, FA_SKIPNETSHARED, FA_SKIPNSTATE, FA_UNKNOWN, fsmFsPath(), fsmGetFi(), IOSM_MAP_PATH, RPMFILE_GHOST, RPMFILE_STATE_NETSHARED, RPMFILE_STATE_NOTINSTALLED, RPMFILE_STATE_WRONGCOLOR, rpmteType(), SUFFIX_RPMNEW, SUFFIX_RPMORIG, SUFFIX_RPMSAVE, and TR_REMOVED.

Referenced by fsmStage().

static int fsmMkdirs | ( | IOSM_t | fsm | ) |

static

Create (if necessary) directories not explicitly included in package.

Parameters

  fsm | file state machine data

Returns
  0 on success

Definition at line 1420 of file fsm.c.

References _free(), D_, dc, dnlCount(), dnlFreeIterator(), dnlIndex(), dnlInitIterator(), dnlNextIterator(), fsmGetFi(), fsmNext(), fsmUNSAFE, IOSM_LSETFCON, IOSM_LSTAT, IOSM_MKDIR, matchpathcon, rpmlog(), RPMLOG_DEBUG, stpcpy(), urlPath(), xcalloc(), and xrealloc().

Referenced by fsmStage().

int fsmNext | ( | IOSM_t | fsm,
|  | iosmFileStage | nstage
| ) |  |

File state machine driver.

Parameters

  fsm | file state machine
  nstage | next stage

Returns
  0 on success

Definition at line 428 of file fsm.c.

References fsmStage(), rpmsqJoin(), and rpmsqThread().

Referenced by extractRegular(), fsmCommitLinks(), fsmMakeLinks(), fsmMkdirs(), fsmRmdirs(), fsmSetup(), fsmStage(), saveHardLink(), writeFile(), and writeLinkedFile().

static int fsmRmdirs | ( | IOSM_t | fsm | ) |

static

Remove (if created) directories not explicitly included in package.

Parameters

  fsm | file state machine data

Returns
  0 on success

Definition at line 1365 of file fsm.c.

References dc, dnlCount(), dnlFreeIterator(), dnlIndex(), dnlInitIterator(), dnlNextIterator(), fsmNext(), IOSM_RMDIR, and stpcpy().

Referenced by fsmStage().

int fsmSetup | ( | void * | _fsm,
|  | iosmFileStage | goal,
|  | const char * | afmt,
|  | const void * | _ts,
|  | const void * | _fi,
|  | FD_t | cfd,
|  | unsigned int * | archiveSize,
|  | const char ** | failedFile
| ) |  |

Load external data into file state machine.

Parameters

  _fsm | file state machine
  goal |
  afmt | archive format (NULL uses cpio)
  _ts | transaction set
  _fi | transaction element file info
  cfd | payload descriptor

Return values

  archiveSize | pointer to archive size
  failedFile | pointer to first file name that failed.

Returns
  0 on success

Definition at line 617 of file fsm.c.

References _fsm_debug, _fsm_threads, _iosmNext, _tsmask, arHeaderRead(), arHeaderWrite(), arSetup(), arTrailerWrite(), cpioHeaderRead(), cpioHeaderWrite(), cpioTrailerWrite(), FA_COPYOUT, fdGetCpioPos(), fdLink(), fdSetCpioPos(), fsmNext(), fsmUNSAFE, IOSM_CREATE, IOSM_PKGBUILD, IOSM_PKGCOMMIT, IOSM_PKGERASE, IOSM_PKGINSTALL, mapInitIterator(), reverse, RPMCALLBACK_INST_START, rpmteType(), RPMTRANS_FLAG_NOCONTEXTS, RPMTRANS_FLAG_NOFDIGESTS, rpmtsFlags(), rpmtsGetTid(), rpmtsLink(), rpmtsNotify(), TAR_BLOCK_SIZE, tarHeaderRead(), tarHeaderWrite(), tarTrailerWrite(), TR_ADDED, and TR_REMOVED.

Referenced by cpio_doio(), and rpmpsmStage().

int fsmStage | ( | IOSM_t | fsm,
|  | iosmFileStage | stage
| ) |  |

File state machine driver.

Parameters

  fsm | file state machine
  stage | next stage

Returns
  0 on success

Definition at line 1590 of file fsm.c.

References _, _fafilter, _free(), alloca(), errno, extractRegular(), FA_ERASE, FA_UNKNOWN, fdGetCpioPos(), freeHardLink(), fsmCommitLinks(), fsmFsPath(), fsmGetFi(), fsmGetTs(), fsmMakeLinks(), fsmMapAttrs(), fsmMapFContext(), fsmMapPath(), fsmMkdirs(), fsmNext(), fsmRmdirs(), fsmUNSAFE, IOSM_ALL_HARDLINKS, IOSM_CHMOD, IOSM_CHOWN, IOSM_CHROOT, IOSM_COMMIT, IOSM_CREATE, IOSM_DEAD, IOSM_DESTROY, IOSM_DREAD, IOSM_DWRITE, IOSM_EAT, IOSM_FINI, IOSM_FOLLOW_SYMLINKS, IOSM_HREAD, IOSM_HWRITE, IOSM_INIT, IOSM_INTERNAL, IOSM_LCHOWN, IOSM_LINK, IOSM_LSETFCON, IOSM_LSTAT, IOSM_MAP, IOSM_MKDIR, IOSM_MKDIRS, IOSM_MKFIFO, IOSM_MKLINKS, IOSM_MKNOD, IOSM_NEXT, IOSM_NOTIFY, IOSM_PAD, IOSM_PAYLOAD_EXTRACT, IOSM_PAYLOAD_LIST, IOSM_PKGBUILD, IOSM_PKGCOMMIT, IOSM_PKGERASE, IOSM_PKGINSTALL, IOSM_POS, IOSM_POST, IOSM_PRE, IOSM_PROCESS, IOSM_RCLOSE, IOSM_READ, IOSM_READLINK, IOSM_RENAME, IOSM_RMDIR, IOSM_RMDIRS, IOSM_ROPEN, IOSM_STAT, IOSM_SYMLINK, IOSM_SYSCALL, IOSM_TRAILER, IOSM_UNDO, IOSM_UNKNOWN, IOSM_UNLINK, IOSM_UTIME, IOSM_VERBOSE, IOSM_VERIFY, IOSM_WCLOSE, IOSM_WOPEN, IOSM_WRITE, iosmFileActionSkipped(), iosmFileStageString(), iosmStage(), IS_DEV_LOG, mapFind(), mapNextIterator(), RPMCALLBACK_INST_PROGRESS, RPMFILE_GHOST, RPMFILE_MISSINGOK, rpmfiTypeString(), rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, RPMLOG_WARNING, rpmtsNotify(), S_ISLNK, S_ISSOCK, saveHardLink(), stpcpy(), Unlink(), urlPath(), writeFile(), writeLinkedFile(), xmalloc(), and xstrdup().

Referenced by fsmNext().

int fsmTeardown | ( | void * | _fsm | ) |

Clean file state machine.

Parameters

  _fsm | file state machine

Returns
  0 on success

Definition at line 741 of file fsm.c.

References _free(), fdFree(), fsmGetTs(), fsmUNSAFE, IOSM_DESTROY, mapFreeIterator(), rpmswAdd(), RPMTS_OP_DIGEST, rpmtsFree(), and rpmtsOp().

Referenced by cpio_doio(), and rpmpsmStage().

IOSM_t newFSM | ( | void |  | ) |

Create file state machine instance.

Returns
  file state machine

Definition at line 541 of file fsm.c.

References xcalloc().

Referenced by rpmfiNew().

## Variable Documentation

int _fsm_debug = 0

Definition at line 52 of file fsm.c.

Referenced by fsmSetup().

int _fsm_threads = 0

Definition at line 56 of file fsm.c.

Referenced by fsmSetup().