2002-05-17 00:55:21 +08:00
|
|
|
/** \ingroup rpmts payload
|
2001-02-11 00:47:40 +08:00
|
|
|
* \file lib/psm.c
|
2001-04-10 20:36:45 +08:00
|
|
|
* Package state machine to handle a package from a transaction set.
|
2000-08-28 03:27:03 +08:00
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-01-18 00:22:57 +08:00
|
|
|
|
2002-04-13 09:28:20 +08:00
|
|
|
#include <rpmio_internal.h>
|
|
|
|
#include <rpmlib.h>
|
2002-07-14 03:08:51 +08:00
|
|
|
#include <rpmmacro.h>
|
|
|
|
#include <rpmurl.h>
|
2004-03-20 04:08:20 +08:00
|
|
|
#include <rpmlua.h>
|
2002-05-20 02:42:25 +08:00
|
|
|
|
2002-04-13 09:28:20 +08:00
|
|
|
#include "cpio.h"
|
|
|
|
#include "fsm.h" /* XXX CPIO_FOO/FSM_FOO constants */
|
2001-09-26 04:51:34 +08:00
|
|
|
#include "psm.h"
|
1996-01-09 03:31:44 +08:00
|
|
|
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "rpmds.h"
|
2002-05-20 07:37:24 +08:00
|
|
|
|
|
|
|
#define _RPMFI_INTERNAL
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "rpmfi.h"
|
2002-05-20 07:37:24 +08:00
|
|
|
|
|
|
|
#define _RPMTE_INTERNAL
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "rpmte.h"
|
2002-08-05 00:55:55 +08:00
|
|
|
|
|
|
|
#define _RPMTS_INTERNAL /* XXX ts->notify */
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "rpmts.h"
|
2001-11-03 05:01:25 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
#include "rpmlead.h" /* writeLead proto */
|
|
|
|
#include "signature.h" /* signature constants */
|
2002-12-19 06:54:00 +08:00
|
|
|
#include "legacy.h" /* XXX rpmfiBuildFNames() */
|
2001-10-22 05:43:32 +08:00
|
|
|
#include "misc.h" /* XXX stripTrailingChar() */
|
2001-07-28 08:33:07 +08:00
|
|
|
#include "rpmdb.h" /* XXX for db_chrootDone */
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-01-09 03:31:44 +08:00
|
|
|
|
2002-09-01 06:39:34 +08:00
|
|
|
#define _PSM_DEBUG 0
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@unchecked@*/
|
2002-09-01 06:39:34 +08:00
|
|
|
int _psm_debug = _PSM_DEBUG;
|
2003-03-20 00:05:49 +08:00
|
|
|
/*@unchecked@*/
|
|
|
|
int _psm_threads = 0;
|
2002-08-20 06:27:44 +08:00
|
|
|
|
2004-03-06 02:22:25 +08:00
|
|
|
/* Give access to the rpmte global tracking the last instance added
|
|
|
|
* to the database.
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@-exportheadervar@*/
|
|
|
|
/*@unchecked@*/
|
2004-03-06 02:22:25 +08:00
|
|
|
extern unsigned int myinstall_instance;
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@=exportheadervar@*/
|
2004-03-06 02:22:25 +08:00
|
|
|
|
2003-01-24 04:23:24 +08:00
|
|
|
/*@access FD_t @*/ /* XXX void ptr args */
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@access rpmpsm @*/
|
2001-11-05 06:00:11 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
/*@access rpmfi @*/
|
|
|
|
/*@access rpmte @*/ /* XXX rpmInstallSourcePackage */
|
2002-08-09 00:06:13 +08:00
|
|
|
/*@access rpmts @*/ /* XXX ts->notify */
|
2001-11-12 00:17:57 +08:00
|
|
|
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@access rpmluav @*/
|
|
|
|
/*@access rpmtsScore @*/
|
|
|
|
/*@access rpmtsScoreEntry @*/
|
|
|
|
|
2001-03-05 01:15:56 +08:00
|
|
|
int rpmVersionCompare(Header first, Header second)
|
|
|
|
{
|
|
|
|
const char * one, * two;
|
|
|
|
int_32 * epochOne, * epochTwo;
|
2007-06-11 15:30:29 +08:00
|
|
|
static int_32 zero = 0;
|
2004-04-01 20:56:54 +08:00
|
|
|
int rc;
|
2001-03-05 01:15:56 +08:00
|
|
|
|
|
|
|
if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
|
2007-06-11 15:30:29 +08:00
|
|
|
epochOne = &zero;
|
2003-04-05 06:15:58 +08:00
|
|
|
if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo, NULL))
|
2007-06-11 15:30:29 +08:00
|
|
|
epochTwo = &zero;
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2002-07-03 07:54:35 +08:00
|
|
|
/*@-boundsread@*/
|
2001-03-05 01:15:56 +08:00
|
|
|
if (*epochOne < *epochTwo)
|
2004-04-01 20:56:54 +08:00
|
|
|
return -1;
|
2001-03-05 01:15:56 +08:00
|
|
|
else if (*epochOne > *epochTwo)
|
2004-04-01 20:56:54 +08:00
|
|
|
return 1;
|
2002-07-03 07:54:35 +08:00
|
|
|
/*@=boundsread@*/
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
rc = headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
|
|
|
|
rc = headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
|
2001-03-05 01:15:56 +08:00
|
|
|
|
|
|
|
rc = rpmvercmp(one, two);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
rc = headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
|
|
|
|
rc = headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2004-04-01 20:56:54 +08:00
|
|
|
return rpmvercmp(one, two);
|
2001-03-05 01:15:56 +08:00
|
|
|
}
|
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
|
|
|
* Macros to be defined from per-header tag values.
|
2001-01-26 04:26:35 +08:00
|
|
|
* @todo Should other macros be added from header when installing a package?
|
2000-08-23 21:02:13 +08:00
|
|
|
*/
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@observer@*/ /*@unchecked@*/
|
1999-04-03 08:05:03 +08:00
|
|
|
static struct tagMacro {
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@observer@*/ /*@null@*/ const char * macroname; /*!< Macro name to define. */
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTag tag; /*!< Header tag to use for value. */
|
1999-04-03 08:05:03 +08:00
|
|
|
} tagMacros[] = {
|
2001-06-06 03:26:22 +08:00
|
|
|
{ "name", RPMTAG_NAME },
|
|
|
|
{ "version", RPMTAG_VERSION },
|
|
|
|
{ "release", RPMTAG_RELEASE },
|
|
|
|
{ "epoch", RPMTAG_EPOCH },
|
|
|
|
{ NULL, 0 }
|
1999-04-03 08:05:03 +08:00
|
|
|
};
|
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
|
|
|
* Define per-header macros.
|
2001-06-12 12:10:21 +08:00
|
|
|
* @param fi transaction element file info
|
2000-08-23 21:02:13 +08:00
|
|
|
* @param h header
|
|
|
|
* @return 0 always
|
|
|
|
*/
|
2002-05-20 02:42:25 +08:00
|
|
|
static int rpmInstallLoadMacros(rpmfi fi, Header h)
|
2002-04-12 00:55:19 +08:00
|
|
|
/*@globals rpmGlobalMacroContext @*/
|
|
|
|
/*@modifies rpmGlobalMacroContext @*/
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-06-12 12:10:21 +08:00
|
|
|
HGE_t hge = (HGE_t) fi->hge;
|
|
|
|
struct tagMacro * tagm;
|
2000-05-13 07:30:28 +08:00
|
|
|
union {
|
2001-06-12 12:10:21 +08:00
|
|
|
/*@unused@*/ void * ptr;
|
|
|
|
/*@unused@*/ const char ** argv;
|
|
|
|
const char * str;
|
2001-01-21 23:43:32 +08:00
|
|
|
int_32 * i32p;
|
2000-05-13 07:30:28 +08:00
|
|
|
} body;
|
1999-08-09 22:28:13 +08:00
|
|
|
char numbuf[32];
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType type;
|
1999-04-03 08:05:03 +08:00
|
|
|
|
|
|
|
for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
|
2001-02-06 06:22:43 +08:00
|
|
|
if (!hge(h, tagm->tag, &type, (void **) &body, NULL))
|
1999-08-09 22:28:13 +08:00
|
|
|
continue;
|
|
|
|
switch (type) {
|
|
|
|
case RPM_INT32_TYPE:
|
2002-07-03 07:54:35 +08:00
|
|
|
/*@-boundsread@*/
|
2001-01-21 23:43:32 +08:00
|
|
|
sprintf(numbuf, "%d", *body.i32p);
|
2002-07-03 07:54:35 +08:00
|
|
|
/*@=boundsread@*/
|
2000-05-13 07:30:28 +08:00
|
|
|
addMacro(NULL, tagm->macroname, NULL, numbuf, -1);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1999-08-09 22:28:13 +08:00
|
|
|
case RPM_STRING_TYPE:
|
2001-06-12 12:10:21 +08:00
|
|
|
addMacro(NULL, tagm->macroname, NULL, body.str, -1);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2001-06-12 12:10:21 +08:00
|
|
|
case RPM_NULL_TYPE:
|
|
|
|
case RPM_CHAR_TYPE:
|
|
|
|
case RPM_INT8_TYPE:
|
|
|
|
case RPM_INT16_TYPE:
|
|
|
|
case RPM_BIN_TYPE:
|
|
|
|
case RPM_STRING_ARRAY_TYPE:
|
|
|
|
case RPM_I18NSTRING_TYPE:
|
|
|
|
default:
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1999-04-03 08:05:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-24 21:46:51 +08:00
|
|
|
/**
|
2001-01-22 07:48:09 +08:00
|
|
|
* Mark files in database shared with this package as "replaced".
|
2001-03-03 00:17:03 +08:00
|
|
|
* @param psm package state machine data
|
2000-10-24 21:46:51 +08:00
|
|
|
* @return 0 always
|
|
|
|
*/
|
2002-06-20 02:52:46 +08:00
|
|
|
/*@-bounds@*/
|
2002-08-24 05:01:59 +08:00
|
|
|
static rpmRC markReplacedFiles(const rpmpsm psm)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
|
2002-07-22 06:06:19 +08:00
|
|
|
/*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
const rpmts ts = psm->ts;
|
|
|
|
rpmfi fi = psm->fi;
|
2001-02-06 06:22:43 +08:00
|
|
|
HGE_t hge = (HGE_t)fi->hge;
|
2001-11-11 20:47:08 +08:00
|
|
|
sharedFileInfo replaced = fi->replaced;
|
|
|
|
sharedFileInfo sfi;
|
2000-04-27 20:50:54 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
Header h;
|
2007-07-11 18:13:35 +08:00
|
|
|
int * offsets;
|
2000-07-16 00:00:14 +08:00
|
|
|
unsigned int prev;
|
2001-10-16 22:58:57 +08:00
|
|
|
int num, xx;
|
2000-04-27 20:50:54 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
if (!(rpmfiFC(fi) > 0 && fi->replaced))
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_OK;
|
2001-01-22 07:48:09 +08:00
|
|
|
|
2000-07-16 00:00:14 +08:00
|
|
|
num = prev = 0;
|
2001-01-22 07:48:09 +08:00
|
|
|
for (sfi = replaced; sfi->otherPkg; sfi++) {
|
|
|
|
if (prev && prev == sfi->otherPkg)
|
2000-07-16 00:00:14 +08:00
|
|
|
continue;
|
2001-01-22 07:48:09 +08:00
|
|
|
prev = sfi->otherPkg;
|
2000-04-27 20:50:54 +08:00
|
|
|
num++;
|
2000-07-16 00:00:14 +08:00
|
|
|
}
|
2000-07-16 02:15:23 +08:00
|
|
|
if (num == 0)
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_OK;
|
2000-07-16 00:00:14 +08:00
|
|
|
|
2000-04-27 20:50:54 +08:00
|
|
|
offsets = alloca(num * sizeof(*offsets));
|
2002-04-15 05:48:44 +08:00
|
|
|
offsets[0] = 0;
|
2000-07-16 00:00:14 +08:00
|
|
|
num = prev = 0;
|
2001-01-22 07:48:09 +08:00
|
|
|
for (sfi = replaced; sfi->otherPkg; sfi++) {
|
|
|
|
if (prev && prev == sfi->otherPkg)
|
2000-07-16 00:00:14 +08:00
|
|
|
continue;
|
2001-01-22 07:48:09 +08:00
|
|
|
prev = sfi->otherPkg;
|
|
|
|
offsets[num++] = sfi->otherPkg;
|
2000-07-16 00:00:14 +08:00
|
|
|
}
|
2000-04-27 20:50:54 +08:00
|
|
|
|
2001-10-28 04:09:20 +08:00
|
|
|
mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = rpmdbAppendIterator(mi, offsets, num);
|
|
|
|
xx = rpmdbSetIteratorRewrite(mi, 1);
|
2000-04-27 20:50:54 +08:00
|
|
|
|
2001-01-22 07:48:09 +08:00
|
|
|
sfi = replaced;
|
2000-04-27 20:50:54 +08:00
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
char * secStates;
|
|
|
|
int modified;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
modified = 0;
|
2000-07-17 08:40:17 +08:00
|
|
|
|
2001-02-06 06:22:43 +08:00
|
|
|
if (!hge(h, RPMTAG_FILESTATES, NULL, (void **)&secStates, &count))
|
2000-07-17 08:40:17 +08:00
|
|
|
continue;
|
|
|
|
|
2000-07-16 00:00:14 +08:00
|
|
|
prev = rpmdbGetIteratorOffset(mi);
|
2000-07-16 02:15:23 +08:00
|
|
|
num = 0;
|
2001-01-22 07:48:09 +08:00
|
|
|
while (sfi->otherPkg && sfi->otherPkg == prev) {
|
|
|
|
assert(sfi->otherFileNum < count);
|
|
|
|
if (secStates[sfi->otherFileNum] != RPMFILE_STATE_REPLACED) {
|
|
|
|
secStates[sfi->otherFileNum] = RPMFILE_STATE_REPLACED;
|
2000-07-17 08:40:17 +08:00
|
|
|
if (modified == 0) {
|
|
|
|
/* Modified header will be rewritten. */
|
|
|
|
modified = 1;
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = rpmdbSetIteratorModified(mi, modified);
|
2000-07-17 08:40:17 +08:00
|
|
|
}
|
2000-07-16 02:15:23 +08:00
|
|
|
num++;
|
|
|
|
}
|
2001-01-22 07:48:09 +08:00
|
|
|
sfi++;
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
1997-07-16 09:44:27 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
1997-07-16 09:44:27 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_OK;
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
2002-06-20 02:52:46 +08:00
|
|
|
/*@=bounds@*/
|
1998-01-29 00:49:43 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd,
|
2002-03-14 04:01:50 +08:00
|
|
|
const char ** specFilePtr, const char ** cookie)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-11-12 04:45:20 +08:00
|
|
|
int scareMem = 1;
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmfi fi = NULL;
|
2001-03-05 01:15:56 +08:00
|
|
|
const char * _sourcedir = NULL;
|
|
|
|
const char * _specdir = NULL;
|
1999-09-18 06:01:34 +08:00
|
|
|
const char * specFile = NULL;
|
2001-03-05 01:15:56 +08:00
|
|
|
HGE_t hge;
|
|
|
|
HFD_t hfd;
|
2001-10-04 00:11:27 +08:00
|
|
|
Header h = NULL;
|
2002-08-20 06:27:44 +08:00
|
|
|
struct rpmpsm_s psmbuf;
|
|
|
|
rpmpsm psm = &psmbuf;
|
2001-03-05 01:15:56 +08:00
|
|
|
int isSource;
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmRC rpmrc;
|
2001-10-28 04:09:20 +08:00
|
|
|
int i;
|
1996-02-15 01:54:37 +08:00
|
|
|
|
2002-12-02 23:04:16 +08:00
|
|
|
memset(psm, 0, sizeof(*psm));
|
|
|
|
psm->ts = rpmtsLink(ts, "InstallSourcePackage");
|
|
|
|
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = rpmReadPackageFile(ts, fd, "InstallSourcePackage", &h);
|
|
|
|
switch (rpmrc) {
|
2002-08-24 05:01:59 +08:00
|
|
|
case RPMRC_NOTTRUSTED:
|
|
|
|
case RPMRC_NOKEY:
|
|
|
|
case RPMRC_OK:
|
|
|
|
break;
|
|
|
|
default:
|
1999-01-06 07:13:56 +08:00
|
|
|
goto exit;
|
2002-08-24 05:01:59 +08:00
|
|
|
/*@notreached@*/ break;
|
2001-10-26 12:16:19 +08:00
|
|
|
}
|
2002-08-24 05:01:59 +08:00
|
|
|
if (h == NULL)
|
|
|
|
goto exit;
|
|
|
|
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = RPMRC_OK;
|
2002-08-24 05:01:59 +08:00
|
|
|
|
2001-10-26 12:16:19 +08:00
|
|
|
isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
|
1997-02-12 13:05:13 +08:00
|
|
|
|
2001-03-05 01:15:56 +08:00
|
|
|
if (!isSource) {
|
|
|
|
rpmError(RPMERR_NOTSRPM, _("source package expected, binary found\n"));
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = RPMRC_FAIL;
|
1999-01-06 07:13:56 +08:00
|
|
|
goto exit;
|
1997-02-12 13:05:13 +08:00
|
|
|
}
|
1996-02-15 01:54:37 +08:00
|
|
|
|
2007-05-24 15:56:53 +08:00
|
|
|
if (rpmtsAddInstallElement(ts, h, NULL, 0, NULL)) {
|
|
|
|
rpmrc = RPMRC_FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
2001-10-31 02:00:21 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
|
2002-07-14 03:08:51 +08:00
|
|
|
h = headerFree(h);
|
2001-11-13 04:51:05 +08:00
|
|
|
|
2001-11-12 04:45:20 +08:00
|
|
|
if (fi == NULL) { /* XXX can't happen */
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = RPMRC_FAIL;
|
2001-11-12 04:45:20 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
/*@-onlytrans@*/ /* FIX: te reference */
|
|
|
|
fi->te = rpmtsElement(ts, 0);
|
|
|
|
/*@=onlytrans@*/
|
2003-04-03 05:16:26 +08:00
|
|
|
if (fi->te == NULL) { /* XXX can't happen */
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = RPMRC_FAIL;
|
2003-04-03 05:16:26 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
/*@-nullpass@*/ /* FIX fi->h may be null */
|
2002-07-14 03:08:51 +08:00
|
|
|
fi->te->h = headerLink(fi->h);
|
2002-05-20 07:37:24 +08:00
|
|
|
/*@=nullpass@*/
|
2002-04-12 00:55:19 +08:00
|
|
|
fi->te->fd = fdLink(fd, "installSourcePackage");
|
2001-11-12 04:45:20 +08:00
|
|
|
hge = fi->hge;
|
|
|
|
hfd = fi->hfd;
|
|
|
|
|
|
|
|
/*@i@*/ (void) rpmInstallLoadMacros(fi, fi->h);
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2003-01-24 04:23:24 +08:00
|
|
|
psm->fi = rpmfiLink(fi, NULL);
|
2001-11-12 04:45:20 +08:00
|
|
|
/*@-assignexpose -usereleased @*/
|
2001-11-12 00:17:57 +08:00
|
|
|
psm->te = fi->te;
|
2001-11-12 04:45:20 +08:00
|
|
|
/*@=assignexpose =usereleased @*/
|
2001-03-05 01:15:56 +08:00
|
|
|
|
|
|
|
if (cookie) {
|
|
|
|
*cookie = NULL;
|
2001-05-23 22:25:19 +08:00
|
|
|
if (hge(fi->h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL))
|
2001-03-05 01:15:56 +08:00
|
|
|
*cookie = xstrdup(*cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX FIXME: can't do endian neutral MD5 verification yet. */
|
2001-11-12 04:45:20 +08:00
|
|
|
/*@i@*/ fi->fmd5s = hfd(fi->fmd5s, -1);
|
2001-03-05 01:15:56 +08:00
|
|
|
|
|
|
|
/* XXX FIXME: don't do per-file mapping, force global flags. */
|
2001-06-26 04:01:42 +08:00
|
|
|
fi->fmapflags = _free(fi->fmapflags);
|
2001-03-05 01:15:56 +08:00
|
|
|
fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
|
|
|
|
|
|
|
|
fi->uid = getuid();
|
|
|
|
fi->gid = getgid();
|
|
|
|
fi->astriplen = 0;
|
|
|
|
fi->striplen = 0;
|
|
|
|
|
2001-11-13 04:51:05 +08:00
|
|
|
for (i = 0; i < fi->fc; i++)
|
2001-03-05 01:15:56 +08:00
|
|
|
fi->actions[i] = FA_CREATE;
|
|
|
|
|
2001-01-24 07:03:28 +08:00
|
|
|
i = fi->fc;
|
2001-10-19 00:39:54 +08:00
|
|
|
|
|
|
|
if (fi->h != NULL) { /* XXX can't happen */
|
2002-12-19 06:54:00 +08:00
|
|
|
rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
|
2001-10-19 00:39:54 +08:00
|
|
|
|
|
|
|
if (headerIsEntry(fi->h, RPMTAG_COOKIE))
|
|
|
|
for (i = 0; i < fi->fc; i++)
|
2001-01-24 23:58:35 +08:00
|
|
|
if (fi->fflags[i] & RPMFILE_SPECFILE) break;
|
2001-10-19 00:39:54 +08:00
|
|
|
}
|
1997-10-29 23:53:35 +08:00
|
|
|
|
2001-01-24 07:03:28 +08:00
|
|
|
if (i == fi->fc) {
|
2001-02-02 23:04:44 +08:00
|
|
|
/* Find the spec file by name. */
|
2001-01-24 23:58:35 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
2001-01-24 07:03:28 +08:00
|
|
|
const char * t = fi->apath[i];
|
|
|
|
t += strlen(fi->apath[i]) - 5;
|
|
|
|
if (!strcmp(t, ".spec")) break;
|
1997-05-07 02:19:19 +08:00
|
|
|
}
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
1997-05-07 02:19:19 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
_sourcedir = rpmGenPath(rpmtsRootDir(ts), "%{_sourcedir}", "");
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = rpmMkdirPath(_sourcedir, "sourcedir");
|
|
|
|
if (rpmrc) {
|
|
|
|
rpmrc = RPMRC_FAIL;
|
2001-03-05 01:15:56 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
_specdir = rpmGenPath(rpmtsRootDir(ts), "%{_specdir}", "");
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = rpmMkdirPath(_specdir, "specdir");
|
|
|
|
if (rpmrc) {
|
|
|
|
rpmrc = RPMRC_FAIL;
|
2001-03-05 01:15:56 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2001-01-26 04:26:35 +08:00
|
|
|
/* Build dnl/dil with {_sourcedir, _specdir} as values. */
|
2001-01-24 07:03:28 +08:00
|
|
|
if (i < fi->fc) {
|
2001-01-26 04:26:35 +08:00
|
|
|
int speclen = strlen(_specdir) + 2;
|
|
|
|
int sourcelen = strlen(_sourcedir) + 2;
|
|
|
|
char * t;
|
|
|
|
|
2001-11-12 04:45:20 +08:00
|
|
|
/*@i@*/ fi->dnl = hfd(fi->dnl, -1);
|
2001-01-26 04:26:35 +08:00
|
|
|
|
|
|
|
fi->dc = 2;
|
2003-01-24 04:23:24 +08:00
|
|
|
fi->dnl = xmalloc(fi->dc * sizeof(*fi->dnl)
|
|
|
|
+ fi->fc * sizeof(*fi->dil)
|
|
|
|
+ speclen + sourcelen);
|
|
|
|
/*@-dependenttrans@*/
|
2007-07-11 18:20:45 +08:00
|
|
|
fi->dil = (unsigned int *)(fi->dnl + fi->dc);
|
2003-01-24 04:23:24 +08:00
|
|
|
/*@=dependenttrans@*/
|
2001-01-26 04:26:35 +08:00
|
|
|
memset(fi->dil, 0, fi->fc * sizeof(*fi->dil));
|
|
|
|
fi->dil[i] = 1;
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-dependenttrans@*/
|
2001-01-26 04:26:35 +08:00
|
|
|
fi->dnl[0] = t = (char *)(fi->dil + fi->fc);
|
|
|
|
fi->dnl[1] = t = stpcpy( stpcpy(t, _sourcedir), "/") + 1;
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=dependenttrans@*/
|
2001-01-26 04:26:35 +08:00
|
|
|
(void) stpcpy( stpcpy(t, _specdir), "/");
|
|
|
|
|
|
|
|
t = xmalloc(speclen + strlen(fi->bnl[i]) + 1);
|
|
|
|
(void) stpcpy( stpcpy( stpcpy(t, _specdir), "/"), fi->bnl[i]);
|
|
|
|
specFile = t;
|
2001-01-24 00:07:28 +08:00
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_NOSPEC, _("source package contains no .spec file\n"));
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = RPMRC_FAIL;
|
2001-01-24 00:07:28 +08:00
|
|
|
goto exit;
|
1997-05-07 02:19:19 +08:00
|
|
|
}
|
1996-07-26 00:39:01 +08:00
|
|
|
|
2001-03-05 01:15:56 +08:00
|
|
|
psm->goal = PSM_PKGINSTALL;
|
2001-03-02 00:01:16 +08:00
|
|
|
|
2001-05-23 22:25:19 +08:00
|
|
|
/*@-compmempass@*/ /* FIX: psm->fi->dnl should be owned. */
|
2003-04-17 01:48:04 +08:00
|
|
|
rpmrc = rpmpsmStage(psm, PSM_PROCESS);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
(void) rpmpsmStage(psm, PSM_FINI);
|
2001-05-23 22:25:19 +08:00
|
|
|
/*@=compmempass@*/
|
2001-01-22 07:48:09 +08:00
|
|
|
|
2003-04-17 01:48:04 +08:00
|
|
|
if (rpmrc) rpmrc = RPMRC_FAIL;
|
1996-02-15 04:09:14 +08:00
|
|
|
|
1999-01-06 07:13:56 +08:00
|
|
|
exit:
|
2003-04-17 01:48:04 +08:00
|
|
|
if (specFilePtr && specFile && rpmrc == RPMRC_OK)
|
2001-01-26 04:26:35 +08:00
|
|
|
*specFilePtr = specFile;
|
|
|
|
else
|
2001-02-13 03:02:15 +08:00
|
|
|
specFile = _free(specFile);
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
_specdir = _free(_specdir);
|
|
|
|
_sourcedir = _free(_sourcedir);
|
1996-02-16 05:08:48 +08:00
|
|
|
|
2003-01-24 04:23:24 +08:00
|
|
|
psm->fi = rpmfiFree(psm->fi);
|
|
|
|
psm->te = NULL;
|
|
|
|
|
|
|
|
if (h != NULL) h = headerFree(h);
|
1996-02-16 05:08:48 +08:00
|
|
|
|
2001-11-12 04:45:20 +08:00
|
|
|
/*@-branchstate@*/
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fi != NULL) {
|
2002-07-14 03:08:51 +08:00
|
|
|
fi->te->h = headerFree(fi->te->h);
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fi->te->fd != NULL)
|
2002-04-12 00:55:19 +08:00
|
|
|
(void) Fclose(fi->te->fd);
|
|
|
|
fi->te->fd = NULL;
|
|
|
|
fi->te = NULL;
|
2002-08-20 06:27:44 +08:00
|
|
|
fi = rpmfiFree(fi);
|
2002-04-12 00:55:19 +08:00
|
|
|
}
|
2001-11-12 04:45:20 +08:00
|
|
|
/*@=branchstate@*/
|
2001-03-05 01:15:56 +08:00
|
|
|
|
2002-04-12 00:55:19 +08:00
|
|
|
/* XXX nuke the added package(s). */
|
2002-05-17 00:55:21 +08:00
|
|
|
rpmtsClean(ts);
|
2002-04-12 00:55:19 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
psm->ts = rpmtsFree(psm->ts);
|
2001-10-28 06:31:10 +08:00
|
|
|
|
2003-04-17 01:48:04 +08:00
|
|
|
return rpmrc;
|
2001-01-25 20:58:03 +08:00
|
|
|
}
|
|
|
|
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@observer@*/ /*@unchecked@*/
|
|
|
|
static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin";
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return scriptlet name from tag.
|
|
|
|
* @param tag scriptlet tag
|
|
|
|
* @return name of scriptlet
|
|
|
|
*/
|
2007-07-10 17:15:43 +08:00
|
|
|
static /*@observer@*/ const char * tag2sln(int tag)
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
{
|
|
|
|
switch (tag) {
|
|
|
|
case RPMTAG_PREIN: return "%pre";
|
|
|
|
case RPMTAG_POSTIN: return "%post";
|
|
|
|
case RPMTAG_PREUN: return "%preun";
|
|
|
|
case RPMTAG_POSTUN: return "%postun";
|
|
|
|
case RPMTAG_VERIFYSCRIPT: return "%verify";
|
|
|
|
}
|
|
|
|
return "%unknownscript";
|
|
|
|
}
|
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
/**
|
|
|
|
* Wait for child process to be reaped.
|
|
|
|
* @param psm package state machine data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
static pid_t psmWait(rpmpsm psm)
|
|
|
|
/*@globals fileSystem, internalState @*/
|
|
|
|
/*@modifies psm, fileSystem, internalState @*/
|
|
|
|
{
|
2003-04-03 07:26:06 +08:00
|
|
|
const rpmts ts = psm->ts;
|
|
|
|
rpmtime_t msecs;
|
|
|
|
|
2003-03-18 10:41:33 +08:00
|
|
|
(void) rpmsqWait(&psm->sq);
|
2003-04-03 07:26:06 +08:00
|
|
|
msecs = psm->sq.op.usecs/1000;
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), &psm->sq.op);
|
2002-08-20 06:27:44 +08:00
|
|
|
|
2003-04-03 07:26:06 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("%s: waitpid(%d) rc %d status %x secs %u.%03u\n"),
|
2003-03-18 10:41:33 +08:00
|
|
|
psm->stepName, (unsigned)psm->sq.child,
|
2003-03-25 08:22:23 +08:00
|
|
|
(unsigned)psm->sq.reaped, psm->sq.status,
|
2003-04-03 07:26:06 +08:00
|
|
|
(unsigned)msecs/1000, (unsigned)msecs%1000);
|
2002-08-20 06:27:44 +08:00
|
|
|
|
2003-03-18 10:41:33 +08:00
|
|
|
return psm->sq.reaped;
|
2002-08-20 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2007-05-16 21:16:45 +08:00
|
|
|
#ifdef WITH_LUA
|
2004-03-20 04:08:20 +08:00
|
|
|
/**
|
|
|
|
* Run internal Lua script.
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
static rpmRC runLuaScript(rpmpsm psm, Header h, const char *sln,
|
2004-03-20 04:08:20 +08:00
|
|
|
int progArgc, const char **progArgv,
|
|
|
|
const char *script, int arg1, int arg2)
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@globals fileSystem, internalState @*/
|
|
|
|
/*@modifies psm, fileSystem, internalState @*/
|
2004-03-20 04:08:20 +08:00
|
|
|
{
|
2004-03-25 03:47:11 +08:00
|
|
|
const rpmts ts = psm->ts;
|
2004-03-20 04:08:20 +08:00
|
|
|
int rootFd = -1;
|
|
|
|
const char *n, *v, *r;
|
|
|
|
rpmRC rc = RPMRC_OK;
|
|
|
|
int i;
|
|
|
|
int xx;
|
2004-03-25 03:47:11 +08:00
|
|
|
rpmlua lua = NULL; /* Global state. */
|
2004-03-20 04:08:20 +08:00
|
|
|
rpmluav var;
|
2004-03-27 01:27:57 +08:00
|
|
|
|
2004-03-20 04:08:20 +08:00
|
|
|
xx = headerNVR(h, &n, &v, &r);
|
|
|
|
|
2004-03-25 03:47:11 +08:00
|
|
|
if (!rpmtsChrootDone(ts)) {
|
2004-03-20 04:08:20 +08:00
|
|
|
const char *rootDir = rpmtsRootDir(ts);
|
2004-11-11 11:58:46 +08:00
|
|
|
xx = chdir("/");
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@-nullpass@*/
|
2004-11-11 11:58:46 +08:00
|
|
|
rootFd = open(".", O_RDONLY, 0);
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@=nullpass@*/
|
2004-11-11 11:58:46 +08:00
|
|
|
if (rootFd >= 0) {
|
|
|
|
/*@-superuser -noeffect @*/
|
|
|
|
if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
|
2004-03-27 01:27:57 +08:00
|
|
|
xx = chroot(rootDir);
|
2004-11-11 11:58:46 +08:00
|
|
|
/*@=superuser =noeffect @*/
|
|
|
|
xx = rpmtsSetChrootDone(ts, 1);
|
2004-03-20 04:08:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create arg variable */
|
|
|
|
rpmluaPushTable(lua, "arg");
|
|
|
|
var = rpmluavNew();
|
|
|
|
rpmluavSetListMode(var, 1);
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@+relaxtypes@*/
|
2004-03-20 04:08:20 +08:00
|
|
|
if (progArgv) {
|
|
|
|
for (i = 0; i < progArgc && progArgv[i]; i++) {
|
|
|
|
rpmluavSetValue(var, RPMLUAV_STRING, progArgv[i]);
|
|
|
|
rpmluaSetVar(lua, var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (arg1 >= 0) {
|
|
|
|
rpmluavSetValueNum(var, arg1);
|
|
|
|
rpmluaSetVar(lua, var);
|
|
|
|
}
|
|
|
|
if (arg2 >= 0) {
|
|
|
|
rpmluavSetValueNum(var, arg2);
|
|
|
|
rpmluaSetVar(lua, var);
|
|
|
|
}
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@=relaxtypes@*/
|
|
|
|
/*@-moduncon@*/
|
2004-03-20 04:08:20 +08:00
|
|
|
var = rpmluavFree(var);
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@=moduncon@*/
|
2004-03-20 04:08:20 +08:00
|
|
|
rpmluaPop(lua);
|
|
|
|
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
2004-03-27 01:27:57 +08:00
|
|
|
xx = snprintf(buf, BUFSIZ, "%s(%s-%s-%s)", sln, n, v, r);
|
2004-03-20 04:08:20 +08:00
|
|
|
if (rpmluaRunScript(lua, script, buf) == -1)
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmluaDelVar(lua, "arg");
|
|
|
|
|
|
|
|
if (rootFd >= 0) {
|
2004-11-11 11:58:46 +08:00
|
|
|
const char *rootDir = rpmtsRootDir(ts);
|
2004-03-27 01:27:57 +08:00
|
|
|
xx = fchdir(rootFd);
|
|
|
|
xx = close(rootFd);
|
|
|
|
/*@-superuser -noeffect @*/
|
2004-11-11 11:58:46 +08:00
|
|
|
if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
|
|
|
|
xx = chroot(".");
|
2004-03-27 01:27:57 +08:00
|
|
|
/*@=superuser =noeffect @*/
|
|
|
|
xx = rpmtsSetChrootDone(ts, 0);
|
2004-03-20 04:08:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2007-05-16 21:16:45 +08:00
|
|
|
#endif
|
2004-03-20 04:08:20 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
/*@unchecked@*/
|
|
|
|
static int ldconfig_done = 0;
|
|
|
|
|
2002-08-21 06:05:18 +08:00
|
|
|
/*@unchecked@*/ /*@observer@*/ /*@null@*/
|
2002-08-20 06:27:44 +08:00
|
|
|
static const char * ldconfig_path = "/sbin/ldconfig";
|
|
|
|
|
2001-02-13 00:33:08 +08:00
|
|
|
/**
|
2001-02-28 23:49:23 +08:00
|
|
|
* 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.
|
2004-03-27 01:27:57 +08:00
|
|
|
*
|
2001-02-28 07:12:30 +08:00
|
|
|
* @param psm package state machine data
|
2001-02-28 23:49:23 +08:00
|
|
|
* @param h header
|
|
|
|
* @param sln name of scriptlet section
|
|
|
|
* @param progArgc no. of args from header
|
|
|
|
* @param progArgv args from header, progArgv[0] is the interpreter to use
|
|
|
|
* @param script scriptlet from header
|
|
|
|
* @param arg1 no. instances of package installed after scriptlet exec
|
|
|
|
* (-1 is no arg)
|
|
|
|
* @param arg2 ditto, but for the target package
|
2002-08-24 05:01:59 +08:00
|
|
|
* @return 0 on success
|
2001-02-13 00:33:08 +08:00
|
|
|
*/
|
2002-09-01 06:39:34 +08:00
|
|
|
static rpmRC runScript(rpmpsm psm, Header h, const char * sln,
|
2004-03-27 01:27:57 +08:00
|
|
|
int progArgc, const char ** progArgv,
|
2001-02-28 23:49:23 +08:00
|
|
|
const char * script, int arg1, int arg2)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals ldconfig_done, rpmGlobalMacroContext, h_errno,
|
2002-08-21 06:05:18 +08:00
|
|
|
fileSystem, internalState@*/
|
|
|
|
/*@modifies psm, ldconfig_done, rpmGlobalMacroContext,
|
|
|
|
fileSystem, internalState @*/
|
2001-02-13 00:33:08 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
const rpmts ts = psm->ts;
|
|
|
|
rpmfi fi = psm->fi;
|
2001-02-28 23:49:23 +08:00
|
|
|
HGE_t hge = fi->hge;
|
2001-05-04 05:00:18 +08:00
|
|
|
HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
|
2001-02-28 23:49:23 +08:00
|
|
|
const char ** argv = NULL;
|
|
|
|
int argc = 0;
|
|
|
|
const char ** prefixes = NULL;
|
|
|
|
int numPrefixes;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType ipt;
|
2001-02-28 23:49:23 +08:00
|
|
|
const char * oldPrefix;
|
|
|
|
int maxPrefixLength;
|
|
|
|
int len;
|
|
|
|
char * prefixBuf = NULL;
|
|
|
|
const char * fn = NULL;
|
2003-03-18 10:41:33 +08:00
|
|
|
int xx;
|
|
|
|
int i;
|
2001-02-28 23:49:23 +08:00
|
|
|
int freePrefixes = 0;
|
2002-05-17 00:55:21 +08:00
|
|
|
FD_t scriptFd;
|
2001-02-28 23:49:23 +08:00
|
|
|
FD_t out;
|
2001-03-03 01:27:30 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
2004-10-10 03:40:09 +08:00
|
|
|
const char *n, *v, *r, *a;
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2001-10-19 00:39:54 +08:00
|
|
|
if (progArgv == NULL && script == NULL)
|
2002-08-24 05:01:59 +08:00
|
|
|
return rc;
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2005-07-13 19:15:16 +08:00
|
|
|
/* XXX FIXME: except for %verifyscript, rpmteNEVR can be used. */
|
|
|
|
xx = headerNVR(h, &n, &v, &r);
|
|
|
|
xx = hge(h, RPMTAG_ARCH, NULL, (void **) &a, NULL);
|
|
|
|
|
2004-03-17 05:58:25 +08:00
|
|
|
if (progArgv && strcmp(progArgv[0], "<lua>") == 0) {
|
2007-05-16 21:16:45 +08:00
|
|
|
#ifdef WITH_LUA
|
2004-10-10 03:40:09 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("%s: %s(%s-%s-%s.%s) running <lua> scriptlet.\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag), n, v, r, a);
|
2004-03-25 03:47:11 +08:00
|
|
|
return runLuaScript(psm, h, sln, progArgc, progArgv,
|
2004-03-20 04:08:20 +08:00
|
|
|
script, arg1, arg2);
|
2007-05-16 21:16:45 +08:00
|
|
|
#else
|
|
|
|
return RPMRC_FAIL;
|
|
|
|
#endif
|
2004-03-17 05:58:25 +08:00
|
|
|
}
|
|
|
|
|
2003-03-18 10:41:33 +08:00
|
|
|
psm->sq.reaper = 1;
|
2002-08-20 06:27:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a successor node, and ldconfig was just run, don't bother.
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
if (ldconfig_path && progArgv != NULL && psm->unorderedSuccessor) {
|
2002-08-20 06:27:44 +08:00
|
|
|
if (ldconfig_done && !strcmp(progArgv[0], ldconfig_path)) {
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
2004-10-10 03:40:09 +08:00
|
|
|
_("%s: %s(%s-%s-%s.%s) skipping redundant \"%s\".\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag), n, v, r, a,
|
2002-08-20 06:27:44 +08:00
|
|
|
progArgv[0]);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
2004-10-10 03:40:09 +08:00
|
|
|
_("%s: %s(%s-%s-%s.%s) %ssynchronous scriptlet start\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag), n, v, r, a,
|
2002-08-20 06:27:44 +08:00
|
|
|
(psm->unorderedSuccessor ? "a" : ""));
|
2001-10-19 00:39:54 +08:00
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
if (!progArgv) {
|
2001-10-16 22:58:57 +08:00
|
|
|
argv = alloca(5 * sizeof(*argv));
|
2001-02-28 23:49:23 +08:00
|
|
|
argv[0] = "/bin/sh";
|
|
|
|
argc = 1;
|
2002-08-20 06:27:44 +08:00
|
|
|
ldconfig_done = 0;
|
2001-02-28 23:49:23 +08:00
|
|
|
} else {
|
2001-10-16 22:58:57 +08:00
|
|
|
argv = alloca((progArgc + 4) * sizeof(*argv));
|
|
|
|
memcpy(argv, progArgv, progArgc * sizeof(*argv));
|
2001-02-28 23:49:23 +08:00
|
|
|
argc = progArgc;
|
2002-08-20 06:27:44 +08:00
|
|
|
ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path)
|
|
|
|
? 1 : 0);
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
|
2004-07-06 04:14:28 +08:00
|
|
|
#if __ia64__
|
2004-08-31 23:39:37 +08:00
|
|
|
/* XXX This assumes that all interpreters are elf executables. */
|
|
|
|
if ((a != NULL && a[0] == 'i' && a[1] != '\0' && a[2] == '8' && a[3] == '6')
|
|
|
|
&& strcmp(argv[0], "/sbin/ldconfig"))
|
2004-07-06 04:14:28 +08:00
|
|
|
{
|
|
|
|
const char * fmt = rpmGetPath("%{?_autorelocate_path}", NULL);
|
|
|
|
const char * errstr;
|
|
|
|
char * newPath;
|
|
|
|
char * t;
|
|
|
|
|
|
|
|
newPath = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
|
|
|
|
fmt = _free(fmt);
|
|
|
|
|
|
|
|
/* XXX On ia64, change leading /emul/ix86 -> /emul/ia32, ick. */
|
|
|
|
if (newPath != NULL && *newPath != '\0'
|
|
|
|
&& strlen(newPath) >= (sizeof("/emul/i386")-1)
|
|
|
|
&& newPath[0] == '/' && newPath[1] == 'e' && newPath[2] == 'm'
|
|
|
|
&& newPath[3] == 'u' && newPath[4] == 'l' && newPath[5] == '/'
|
|
|
|
&& newPath[6] == 'i' && newPath[8] == '8' && newPath[9] == '6')
|
|
|
|
{
|
|
|
|
newPath[7] = 'a';
|
|
|
|
newPath[8] = '3';
|
|
|
|
newPath[9] = '2';
|
|
|
|
}
|
|
|
|
|
|
|
|
t = alloca(strlen(newPath) + strlen(argv[0]) + 1);
|
|
|
|
*t = '\0';
|
2004-10-10 03:40:09 +08:00
|
|
|
(void) stpcpy( stpcpy(t, newPath), argv[0]);
|
2004-07-06 04:14:28 +08:00
|
|
|
newPath = _free(newPath);
|
|
|
|
argv[0] = t;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &prefixes, &numPrefixes)) {
|
|
|
|
freePrefixes = 1;
|
|
|
|
} else if (hge(h, RPMTAG_INSTALLPREFIX, NULL, (void **) &oldPrefix, NULL)) {
|
|
|
|
prefixes = &oldPrefix;
|
|
|
|
numPrefixes = 1;
|
|
|
|
} else {
|
|
|
|
numPrefixes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxPrefixLength = 0;
|
2003-04-03 05:16:26 +08:00
|
|
|
if (prefixes != NULL)
|
2001-02-28 23:49:23 +08:00
|
|
|
for (i = 0; i < numPrefixes; i++) {
|
|
|
|
len = strlen(prefixes[i]);
|
|
|
|
if (len > maxPrefixLength) maxPrefixLength = len;
|
|
|
|
}
|
|
|
|
prefixBuf = alloca(maxPrefixLength + 50);
|
|
|
|
|
|
|
|
if (script) {
|
2002-05-20 07:37:24 +08:00
|
|
|
const char * rootDir = rpmtsRootDir(ts);
|
2001-02-28 23:49:23 +08:00
|
|
|
FD_t fd;
|
2002-05-17 00:55:21 +08:00
|
|
|
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2002-05-24 03:42:23 +08:00
|
|
|
if (makeTempFile((!rpmtsChrootDone(ts) ? rootDir : "/"), &fn, &fd)) {
|
2003-04-03 05:16:26 +08:00
|
|
|
if (prefixes != NULL && freePrefixes) free(prefixes);
|
2002-08-24 05:01:59 +08:00
|
|
|
return RPMRC_FAIL;
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
if (rpmIsDebug() &&
|
|
|
|
(!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
|
2001-10-16 22:58:57 +08:00
|
|
|
{
|
|
|
|
static const char set_x[] = "set -x\n";
|
|
|
|
xx = Fwrite(set_x, sizeof(set_x[0]), sizeof(set_x)-1, fd);
|
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
if (ldconfig_path && strstr(script, ldconfig_path) != NULL)
|
|
|
|
ldconfig_done = 1;
|
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fwrite(script, sizeof(script[0]), strlen(script), fd);
|
|
|
|
xx = Fclose(fd);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
{ const char * sn = fn;
|
2002-05-24 03:42:23 +08:00
|
|
|
if (!rpmtsChrootDone(ts) && rootDir != NULL &&
|
2002-05-17 00:55:21 +08:00
|
|
|
!(rootDir[0] == '/' && rootDir[1] == '\0'))
|
2001-02-28 23:49:23 +08:00
|
|
|
{
|
2002-05-17 00:55:21 +08:00
|
|
|
sn += strlen(rootDir)-1;
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
argv[argc++] = sn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg1 >= 0) {
|
|
|
|
char *av = alloca(20);
|
|
|
|
sprintf(av, "%d", arg1);
|
|
|
|
argv[argc++] = av;
|
|
|
|
}
|
|
|
|
if (arg2 >= 0) {
|
|
|
|
char *av = alloca(20);
|
|
|
|
sprintf(av, "%d", arg2);
|
|
|
|
argv[argc++] = av;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
2002-05-24 03:42:23 +08:00
|
|
|
scriptFd = rpmtsScriptFd(ts);
|
2002-05-17 00:55:21 +08:00
|
|
|
if (scriptFd != NULL) {
|
2001-02-28 23:49:23 +08:00
|
|
|
if (rpmIsVerbose()) {
|
2002-05-17 00:55:21 +08:00
|
|
|
out = fdDup(Fileno(scriptFd));
|
2001-02-28 23:49:23 +08:00
|
|
|
} else {
|
|
|
|
out = Fopen("/dev/null", "w.fdio");
|
|
|
|
if (Ferror(out)) {
|
2002-05-17 00:55:21 +08:00
|
|
|
out = fdDup(Fileno(scriptFd));
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out = fdDup(STDOUT_FILENO);
|
|
|
|
}
|
2002-08-24 05:01:59 +08:00
|
|
|
if (out == NULL) return RPMRC_FAIL; /* XXX can't happen */
|
2004-03-27 01:27:57 +08:00
|
|
|
|
2001-12-09 01:21:36 +08:00
|
|
|
/*@-branchstate@*/
|
2003-03-18 10:41:33 +08:00
|
|
|
xx = rpmsqFork(&psm->sq);
|
|
|
|
if (psm->sq.child == 0) {
|
2001-02-28 23:49:23 +08:00
|
|
|
const char * rootDir;
|
|
|
|
int pipes[2];
|
2004-02-23 08:43:45 +08:00
|
|
|
int flag;
|
|
|
|
int fdno;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
pipes[0] = pipes[1] = 0;
|
|
|
|
/* make stdin inaccessible */
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = pipe(pipes);
|
|
|
|
xx = close(pipes[1]);
|
|
|
|
xx = dup2(pipes[0], STDIN_FILENO);
|
|
|
|
xx = close(pipes[0]);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2004-02-23 08:43:45 +08:00
|
|
|
/* XXX Force FD_CLOEXEC on 1st 100 inherited fdno's. */
|
|
|
|
for (fdno = 3; fdno < 100; fdno++) {
|
|
|
|
flag = fcntl(fdno, F_GETFD);
|
|
|
|
if (flag == -1 || (flag & FD_CLOEXEC))
|
|
|
|
continue;
|
|
|
|
xx = fcntl(fdno, F_SETFD, FD_CLOEXEC);
|
|
|
|
/* XXX W2DO? debug msg for inheirited fdno w/o FD_CLOEXEC */
|
|
|
|
}
|
|
|
|
|
2002-05-17 00:55:21 +08:00
|
|
|
if (scriptFd != NULL) {
|
|
|
|
int sfdno = Fileno(scriptFd);
|
2001-10-15 11:22:10 +08:00
|
|
|
int ofdno = Fileno(out);
|
|
|
|
if (sfdno != STDERR_FILENO)
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = dup2(sfdno, STDERR_FILENO);
|
2001-10-15 11:22:10 +08:00
|
|
|
if (ofdno != STDOUT_FILENO)
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = dup2(ofdno, STDOUT_FILENO);
|
2001-02-28 23:49:23 +08:00
|
|
|
/* make sure we don't close stdin/stderr/stdout by mistake! */
|
2003-12-27 09:37:56 +08:00
|
|
|
if (ofdno > STDERR_FILENO && ofdno != sfdno)
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fclose (out);
|
2007-07-09 17:47:25 +08:00
|
|
|
if (sfdno > STDERR_FILENO && ofdno != sfdno)
|
2002-05-17 00:55:21 +08:00
|
|
|
xx = Fclose (scriptFd);
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{ const char *ipath = rpmExpand("PATH=%{_install_script_path}", NULL);
|
|
|
|
const char *path = SCRIPT_PATH;
|
|
|
|
|
|
|
|
if (ipath && ipath[5] != '%')
|
|
|
|
path = ipath;
|
2001-10-16 01:53:34 +08:00
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = doputenv(path);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-modobserver@*/
|
2001-04-29 09:05:43 +08:00
|
|
|
ipath = _free(ipath);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=modobserver@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
|
2003-04-03 05:16:26 +08:00
|
|
|
if (prefixes != NULL)
|
2001-02-28 23:49:23 +08:00
|
|
|
for (i = 0; i < numPrefixes; i++) {
|
|
|
|
sprintf(prefixBuf, "RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = doputenv(prefixBuf);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
/* backwards compatibility */
|
|
|
|
if (i == 0) {
|
|
|
|
sprintf(prefixBuf, "RPM_INSTALL_PREFIX=%s", prefixes[i]);
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = doputenv(prefixBuf);
|
2001-02-13 00:33:08 +08:00
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2004-11-11 11:58:46 +08:00
|
|
|
rootDir = ts->rootDir; /* HACK: rootDir = rpmtsRootDir(ts); instead */
|
2002-05-17 00:55:21 +08:00
|
|
|
if (rootDir != NULL) /* XXX can't happen */
|
2001-02-28 23:49:23 +08:00
|
|
|
switch(urlIsURL(rootDir)) {
|
|
|
|
case URL_IS_PATH:
|
|
|
|
rootDir += sizeof("file://") - 1;
|
|
|
|
rootDir = strchr(rootDir, '/');
|
|
|
|
/*@fallthrough@*/
|
|
|
|
case URL_IS_UNKNOWN:
|
2002-08-20 06:27:44 +08:00
|
|
|
if (!rpmtsChrootDone(ts) &&
|
|
|
|
!(rootDir[0] == '/' && rootDir[1] == '\0'))
|
|
|
|
{
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@-superuser -noeffect @*/
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = chroot(rootDir);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@=superuser =noeffect @*/
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = chdir("/");
|
2004-10-10 03:40:09 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%s: %s(%s-%s-%s.%s)\texecv(%s) pid %d\n"),
|
|
|
|
psm->stepName, sln, n, v, r, a,
|
2002-08-20 06:27:44 +08:00
|
|
|
argv[0], (unsigned)getpid());
|
2004-02-16 11:07:48 +08:00
|
|
|
|
|
|
|
/* XXX Don't mtrace into children. */
|
2002-08-20 06:27:44 +08:00
|
|
|
unsetenv("MALLOC_CHECK_");
|
2004-02-16 11:07:48 +08:00
|
|
|
|
2004-11-11 14:11:37 +08:00
|
|
|
/* Permit libselinux to do the scriptlet exec. */
|
2004-02-16 11:07:48 +08:00
|
|
|
if (rpmtsSELinuxEnabled(ts) == 1) {
|
2005-01-05 01:11:00 +08:00
|
|
|
/*@-moduncon@*/
|
2007-07-12 15:10:25 +08:00
|
|
|
xx = rpm_execcon(0, argv[0], (char ** const) argv, environ);
|
2005-01-05 01:11:00 +08:00
|
|
|
/*@=moduncon@*/
|
2004-02-16 11:07:48 +08:00
|
|
|
if (xx != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-03 05:16:26 +08:00
|
|
|
/*@-nullstate@*/
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = execv(argv[0], (char *const *)argv);
|
2003-04-03 05:16:26 +08:00
|
|
|
/*@=nullstate@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
break;
|
2004-11-04 21:29:11 +08:00
|
|
|
case URL_IS_HTTPS:
|
|
|
|
case URL_IS_HTTP:
|
|
|
|
case URL_IS_FTP:
|
2004-11-29 05:14:41 +08:00
|
|
|
case URL_IS_DASH:
|
|
|
|
case URL_IS_HKP:
|
2001-02-28 23:49:23 +08:00
|
|
|
default:
|
|
|
|
break;
|
2001-02-13 00:33:08 +08:00
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
_exit(-1);
|
|
|
|
/*@notreached@*/
|
|
|
|
}
|
2001-12-09 01:21:36 +08:00
|
|
|
/*@=branchstate@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2007-04-16 19:49:38 +08:00
|
|
|
if (psm->sq.child == (pid_t)-1) {
|
|
|
|
rpmError(RPMERR_FORK, _("Couldn't fork %s: %s\n"), sln, strerror(errno));
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
(void) psmWait(psm);
|
|
|
|
|
2004-08-31 23:39:37 +08:00
|
|
|
/* XXX filter order dependent multilib "other" arch helper error. */
|
|
|
|
if (!(psm->sq.reaped >= 0 && !strcmp(argv[0], "/usr/sbin/glibc_post_upgrade") && WEXITSTATUS(psm->sq.status) == 110)) {
|
2003-03-18 10:41:33 +08:00
|
|
|
if (psm->sq.reaped < 0) {
|
2001-02-28 23:49:23 +08:00
|
|
|
rpmError(RPMERR_SCRIPT,
|
2004-10-10 03:40:09 +08:00
|
|
|
_("%s(%s-%s-%s.%s) scriptlet failed, waitpid(%d) rc %d: %s\n"),
|
|
|
|
sln, n, v, r, a, psm->sq.child, psm->sq.reaped, strerror(errno));
|
2002-08-20 06:27:44 +08:00
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
} else
|
2003-03-18 10:41:33 +08:00
|
|
|
if (!WIFEXITED(psm->sq.status) || WEXITSTATUS(psm->sq.status)) {
|
2005-05-12 00:11:27 +08:00
|
|
|
if (WIFSIGNALED(psm->sq.status)) {
|
|
|
|
rpmError(RPMERR_SCRIPT,
|
|
|
|
_("%s(%s-%s-%s.%s) scriptlet failed, signal %d\n"),
|
|
|
|
sln, n, v, r, a, WTERMSIG(psm->sq.status));
|
|
|
|
} else {
|
2002-08-20 06:27:44 +08:00
|
|
|
rpmError(RPMERR_SCRIPT,
|
2004-10-10 03:40:09 +08:00
|
|
|
_("%s(%s-%s-%s.%s) scriptlet failed, exit status %d\n"),
|
|
|
|
sln, n, v, r, a, WEXITSTATUS(psm->sq.status));
|
2005-05-12 00:11:27 +08:00
|
|
|
}
|
2002-08-20 06:27:44 +08:00
|
|
|
rc = RPMRC_FAIL;
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2004-08-31 23:39:37 +08:00
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2007-04-16 19:49:38 +08:00
|
|
|
exit:
|
2001-02-28 23:49:23 +08:00
|
|
|
if (freePrefixes) prefixes = hfd(prefixes, ipt);
|
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fclose(out); /* XXX dup'd STDOUT_FILENO */
|
2004-03-27 01:27:57 +08:00
|
|
|
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
if (script) {
|
2001-05-01 06:32:22 +08:00
|
|
|
if (!rpmIsDebug())
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = unlink(fn);
|
2001-04-29 09:05:43 +08:00
|
|
|
fn = _free(fn);
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve and run scriptlet from header.
|
|
|
|
* @param psm package state machine data
|
2001-03-03 01:27:30 +08:00
|
|
|
* @return rpmRC return code
|
2001-02-28 23:49:23 +08:00
|
|
|
*/
|
2002-08-20 06:27:44 +08:00
|
|
|
static rpmRC runInstScript(rpmpsm psm)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
|
2001-02-28 23:49:23 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmfi fi = psm->fi;
|
2001-02-28 23:49:23 +08:00
|
|
|
HGE_t hge = fi->hge;
|
2001-05-04 05:00:18 +08:00
|
|
|
HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
|
2001-10-19 00:39:54 +08:00
|
|
|
void ** progArgv;
|
|
|
|
int progArgc;
|
2001-02-28 23:49:23 +08:00
|
|
|
const char ** argv;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType ptt, stt;
|
2001-02-28 23:49:23 +08:00
|
|
|
const char * script;
|
2001-03-03 01:27:30 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
2001-10-16 22:58:57 +08:00
|
|
|
int xx;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* headerGetEntry() sets the data pointer to NULL if the entry does
|
|
|
|
* not exist.
|
|
|
|
*/
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = hge(fi->h, psm->scriptTag, &stt, (void **) &script, NULL);
|
2001-10-19 00:39:54 +08:00
|
|
|
xx = hge(fi->h, psm->progTag, &ptt, (void **) &progArgv, &progArgc);
|
|
|
|
if (progArgv == NULL && script == NULL)
|
|
|
|
goto exit;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2001-10-19 00:39:54 +08:00
|
|
|
if (progArgv && ptt == RPM_STRING_TYPE) {
|
2001-10-16 22:58:57 +08:00
|
|
|
argv = alloca(sizeof(*argv));
|
2001-10-19 00:39:54 +08:00
|
|
|
*argv = (const char *) progArgv;
|
2001-02-28 23:49:23 +08:00
|
|
|
} else {
|
2001-10-19 00:39:54 +08:00
|
|
|
argv = (const char **) progArgv;
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2001-10-19 00:39:54 +08:00
|
|
|
if (fi->h != NULL) /* XXX can't happen */
|
|
|
|
rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), progArgc, argv,
|
2001-02-28 23:49:23 +08:00
|
|
|
script, psm->scriptArg, -1);
|
2001-03-04 04:41:37 +08:00
|
|
|
|
2001-10-19 00:39:54 +08:00
|
|
|
exit:
|
|
|
|
progArgv = hfd(progArgv, ptt);
|
2001-02-28 23:49:23 +08:00
|
|
|
script = hfd(script, stt);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-07-30 07:06:06 +08:00
|
|
|
* Execute triggers.
|
|
|
|
* @todo Trigger on any provides, not just package NVR.
|
2001-02-28 23:49:23 +08:00
|
|
|
* @param psm package state machine data
|
|
|
|
* @param sourceH
|
|
|
|
* @param triggeredH
|
|
|
|
* @param arg2
|
|
|
|
* @param triggersAlreadyRun
|
|
|
|
* @return
|
|
|
|
*/
|
2002-08-24 05:01:59 +08:00
|
|
|
static rpmRC handleOneTrigger(const rpmpsm psm,
|
|
|
|
Header sourceH, Header triggeredH,
|
2001-04-29 09:05:43 +08:00
|
|
|
int arg2, unsigned char * triggersAlreadyRun)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState@*/
|
2002-08-21 06:05:18 +08:00
|
|
|
/*@modifies psm, sourceH, triggeredH, *triggersAlreadyRun,
|
|
|
|
rpmGlobalMacroContext, fileSystem, internalState @*/
|
2001-02-28 23:49:23 +08:00
|
|
|
{
|
2001-11-05 01:00:00 +08:00
|
|
|
int scareMem = 1;
|
2002-05-20 02:42:25 +08:00
|
|
|
const rpmts ts = psm->ts;
|
|
|
|
rpmfi fi = psm->fi;
|
2001-02-28 23:49:23 +08:00
|
|
|
HGE_t hge = fi->hge;
|
2001-05-04 05:00:18 +08:00
|
|
|
HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmds trigger = NULL;
|
2001-02-28 23:49:23 +08:00
|
|
|
const char ** triggerScripts;
|
|
|
|
const char ** triggerProgs;
|
|
|
|
int_32 * triggerIndices;
|
|
|
|
const char * sourceName;
|
2003-12-27 09:37:56 +08:00
|
|
|
const char * triggerName;
|
2001-03-03 01:27:30 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
2001-10-31 12:00:58 +08:00
|
|
|
int xx;
|
2002-07-03 22:01:49 +08:00
|
|
|
int i;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = headerNVR(sourceH, &sourceName, NULL, NULL);
|
2003-12-27 09:37:56 +08:00
|
|
|
xx = headerNVR(triggeredH, &triggerName, NULL, NULL);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
trigger = rpmdsInit(rpmdsNew(triggeredH, RPMTAG_TRIGGERNAME, scareMem));
|
2002-07-30 07:06:06 +08:00
|
|
|
if (trigger == NULL)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
(void) rpmdsSetNoPromote(trigger, 1);
|
|
|
|
|
2002-07-03 22:01:49 +08:00
|
|
|
while ((i = rpmdsNext(trigger)) >= 0) {
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType tit, tst, tpt;
|
2001-11-05 01:00:00 +08:00
|
|
|
const char * Name;
|
2002-05-20 02:42:25 +08:00
|
|
|
int_32 Flags = rpmdsFlags(trigger);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
if ((Name = rpmdsN(trigger)) == NULL)
|
2001-11-05 01:00:00 +08:00
|
|
|
continue; /* XXX can't happen */
|
|
|
|
|
|
|
|
if (strcmp(Name, sourceName))
|
|
|
|
continue;
|
|
|
|
if (!(Flags & psm->sense))
|
|
|
|
continue;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2002-08-21 06:05:18 +08:00
|
|
|
/*
|
|
|
|
* XXX Trigger on any provided dependency, not just the package NEVR.
|
|
|
|
*/
|
|
|
|
if (!rpmdsAnyMatchesDep(sourceH, trigger, 1))
|
2001-02-28 23:49:23 +08:00
|
|
|
continue;
|
|
|
|
|
2001-05-23 22:25:19 +08:00
|
|
|
if (!( hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit,
|
|
|
|
(void **) &triggerIndices, NULL) &&
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst,
|
|
|
|
(void **) &triggerScripts, NULL) &&
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt,
|
|
|
|
(void **) &triggerProgs, NULL))
|
|
|
|
)
|
|
|
|
continue;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
{ int arg1;
|
|
|
|
int index;
|
|
|
|
|
2003-12-27 09:37:56 +08:00
|
|
|
arg1 = rpmdbCountPackages(rpmtsGetRdb(ts), triggerName);
|
2001-02-28 23:49:23 +08:00
|
|
|
if (arg1 < 0) {
|
2001-11-05 01:00:00 +08:00
|
|
|
/* XXX W2DO? fails as "execution of script failed" */
|
2001-03-03 01:27:30 +08:00
|
|
|
rc = RPMRC_FAIL;
|
2001-02-28 23:49:23 +08:00
|
|
|
} else {
|
|
|
|
arg1 += psm->countCorrection;
|
2002-07-03 22:01:49 +08:00
|
|
|
index = triggerIndices[i];
|
2001-04-29 09:05:43 +08:00
|
|
|
if (triggersAlreadyRun == NULL ||
|
|
|
|
triggersAlreadyRun[index] == 0)
|
|
|
|
{
|
2001-02-28 23:49:23 +08:00
|
|
|
rc = runScript(psm, triggeredH, "%trigger", 1,
|
2004-03-27 01:27:57 +08:00
|
|
|
triggerProgs + index, triggerScripts[index],
|
2001-02-28 23:49:23 +08:00
|
|
|
arg1, arg2);
|
2001-04-29 09:05:43 +08:00
|
|
|
if (triggersAlreadyRun != NULL)
|
|
|
|
triggersAlreadyRun[index] = 1;
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerIndices = hfd(triggerIndices, tit);
|
|
|
|
triggerScripts = hfd(triggerScripts, tst);
|
|
|
|
triggerProgs = hfd(triggerProgs, tpt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each target/source header pair can only result in a single
|
|
|
|
* script being run.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
trigger = rpmdsFree(trigger);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run trigger scripts in the database that are fired by this header.
|
|
|
|
* @param psm package state machine data
|
2002-08-24 05:01:59 +08:00
|
|
|
* @return 0 on success
|
2001-02-28 23:49:23 +08:00
|
|
|
*/
|
2002-08-24 05:01:59 +08:00
|
|
|
static rpmRC runTriggers(rpmpsm psm)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno,
|
2001-10-15 11:22:10 +08:00
|
|
|
fileSystem, internalState @*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies psm, rpmGlobalMacroContext,
|
|
|
|
fileSystem, internalState @*/
|
2001-02-28 23:49:23 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
const rpmts ts = psm->ts;
|
|
|
|
rpmfi fi = psm->fi;
|
2002-08-20 06:27:44 +08:00
|
|
|
int numPackage = -1;
|
2001-03-03 01:27:30 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
2002-08-20 06:27:44 +08:00
|
|
|
const char * N = NULL;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
if (psm->te) /* XXX can't happen */
|
|
|
|
N = rpmteN(psm->te);
|
2004-05-04 01:29:16 +08:00
|
|
|
/* XXX: Might need to adjust instance counts four autorollback. */
|
2002-08-20 06:27:44 +08:00
|
|
|
if (N) /* XXX can't happen */
|
|
|
|
numPackage = rpmdbCountPackages(rpmtsGetRdb(ts), N)
|
|
|
|
+ psm->countCorrection;
|
2001-02-28 23:49:23 +08:00
|
|
|
if (numPackage < 0)
|
2002-08-20 06:27:44 +08:00
|
|
|
return RPMRC_NOTFOUND;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2003-04-03 05:16:26 +08:00
|
|
|
if (fi != NULL && fi->h != NULL) /* XXX can't happen */
|
2001-02-28 23:49:23 +08:00
|
|
|
{ Header triggeredH;
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
int countCorrection = psm->countCorrection;
|
|
|
|
|
|
|
|
psm->countCorrection = 0;
|
2002-08-20 06:27:44 +08:00
|
|
|
mi = rpmtsInitIterator(ts, RPMTAG_TRIGGERNAME, N, 0);
|
|
|
|
while((triggeredH = rpmdbNextIterator(mi)) != NULL)
|
2001-02-28 23:49:23 +08:00
|
|
|
rc |= handleOneTrigger(psm, fi->h, triggeredH, numPackage, NULL);
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2001-02-28 23:49:23 +08:00
|
|
|
psm->countCorrection = countCorrection;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run triggers from this header that are fired by headers in the database.
|
|
|
|
* @param psm package state machine data
|
2002-08-24 05:01:59 +08:00
|
|
|
* @return 0 on success
|
2001-02-28 23:49:23 +08:00
|
|
|
*/
|
2002-08-24 05:01:59 +08:00
|
|
|
static rpmRC runImmedTriggers(rpmpsm psm)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno,
|
2001-10-15 11:22:10 +08:00
|
|
|
fileSystem, internalState @*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies psm, rpmGlobalMacroContext,
|
|
|
|
fileSystem, internalState @*/
|
2001-02-28 23:49:23 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
const rpmts ts = psm->ts;
|
|
|
|
rpmfi fi = psm->fi;
|
2001-02-28 23:49:23 +08:00
|
|
|
HGE_t hge = fi->hge;
|
2001-05-04 05:00:18 +08:00
|
|
|
HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
|
2001-02-28 23:49:23 +08:00
|
|
|
const char ** triggerNames;
|
|
|
|
int numTriggers;
|
|
|
|
int_32 * triggerIndices;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType tnt, tit;
|
2001-02-28 23:49:23 +08:00
|
|
|
int numTriggerIndices;
|
2001-04-29 09:05:43 +08:00
|
|
|
unsigned char * triggersRun;
|
2001-03-03 01:27:30 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
if (fi->h == NULL) return rc; /* XXX can't happen */
|
2001-10-19 00:39:54 +08:00
|
|
|
|
2001-05-23 22:25:19 +08:00
|
|
|
if (!( hge(fi->h, RPMTAG_TRIGGERNAME, &tnt,
|
|
|
|
(void **) &triggerNames, &numTriggers) &&
|
|
|
|
hge(fi->h, RPMTAG_TRIGGERINDEX, &tit,
|
|
|
|
(void **) &triggerIndices, &numTriggerIndices))
|
|
|
|
)
|
2002-08-24 05:01:59 +08:00
|
|
|
return rc;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
|
|
|
|
memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
|
|
|
|
|
|
|
|
{ Header sourceH = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numTriggers; i++) {
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
if (triggersRun[triggerIndices[i]] != 0) continue;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2001-10-28 04:09:20 +08:00
|
|
|
mi = rpmtsInitIterator(ts, RPMTAG_NAME, triggerNames[i], 0);
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
while((sourceH = rpmdbNextIterator(mi)) != NULL) {
|
2004-03-27 01:27:57 +08:00
|
|
|
rc |= handleOneTrigger(psm, sourceH, fi->h,
|
2001-02-28 23:49:23 +08:00
|
|
|
rpmdbGetIteratorCount(mi),
|
|
|
|
triggersRun);
|
|
|
|
}
|
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2001-02-13 00:33:08 +08:00
|
|
|
}
|
|
|
|
}
|
2001-03-15 07:09:09 +08:00
|
|
|
triggerIndices = hfd(triggerIndices, tit);
|
2001-02-28 23:49:23 +08:00
|
|
|
triggerNames = hfd(triggerNames, tnt);
|
2001-02-13 00:33:08 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-07-10 17:15:43 +08:00
|
|
|
/*@observer@*/ static const char * pkgStageString(pkgStage a)
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@*/
|
|
|
|
{
|
2001-03-03 03:47:45 +08:00
|
|
|
switch(a) {
|
|
|
|
case PSM_UNKNOWN: return "unknown";
|
|
|
|
|
|
|
|
case PSM_PKGINSTALL: return " install";
|
|
|
|
case PSM_PKGERASE: return " erase";
|
|
|
|
case PSM_PKGCOMMIT: return " commit";
|
|
|
|
case PSM_PKGSAVE: return "repackage";
|
|
|
|
|
|
|
|
case PSM_INIT: return "init";
|
|
|
|
case PSM_PRE: return "pre";
|
|
|
|
case PSM_PROCESS: return "process";
|
|
|
|
case PSM_POST: return "post";
|
|
|
|
case PSM_UNDO: return "undo";
|
|
|
|
case PSM_FINI: return "fini";
|
|
|
|
|
|
|
|
case PSM_CREATE: return "create";
|
|
|
|
case PSM_NOTIFY: return "notify";
|
|
|
|
case PSM_DESTROY: return "destroy";
|
|
|
|
case PSM_COMMIT: return "commit";
|
|
|
|
|
|
|
|
case PSM_CHROOT_IN: return "chrootin";
|
|
|
|
case PSM_CHROOT_OUT: return "chrootout";
|
|
|
|
case PSM_SCRIPT: return "script";
|
|
|
|
case PSM_TRIGGERS: return "triggers";
|
|
|
|
case PSM_IMMED_TRIGGERS: return "immedtriggers";
|
|
|
|
|
|
|
|
case PSM_RPMIO_FLAGS: return "rpmioflags";
|
|
|
|
|
|
|
|
case PSM_RPMDB_LOAD: return "rpmdbload";
|
|
|
|
case PSM_RPMDB_ADD: return "rpmdbadd";
|
|
|
|
case PSM_RPMDB_REMOVE: return "rpmdbremove";
|
|
|
|
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
/*@noteached@*/
|
|
|
|
}
|
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
rpmpsm XrpmpsmUnlink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
|
|
|
|
{
|
|
|
|
if (psm == NULL) return NULL;
|
|
|
|
/*@-modfilesys@*/
|
|
|
|
if (_psm_debug && msg != NULL)
|
|
|
|
fprintf(stderr, "--> psm %p -- %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
|
|
|
|
/*@=modfilesys@*/
|
|
|
|
psm->nrefs--;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmpsm XrpmpsmLink(rpmpsm psm, const char * msg, const char * fn, unsigned ln)
|
|
|
|
{
|
|
|
|
if (psm == NULL) return NULL;
|
|
|
|
psm->nrefs++;
|
|
|
|
|
|
|
|
/*@-modfilesys@*/
|
|
|
|
if (_psm_debug && msg != NULL)
|
|
|
|
fprintf(stderr, "--> psm %p ++ %d %s at %s:%u\n", psm, psm->nrefs, msg, fn, ln);
|
|
|
|
/*@=modfilesys@*/
|
|
|
|
|
|
|
|
/*@-refcounttrans@*/ return psm; /*@=refcounttrans@*/
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmpsm rpmpsmFree(rpmpsm psm)
|
|
|
|
{
|
|
|
|
const char * msg = "rpmpsmFree";
|
|
|
|
if (psm == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (psm->nrefs > 1)
|
|
|
|
return rpmpsmUnlink(psm, msg);
|
|
|
|
|
|
|
|
/*@-nullstate@*/
|
|
|
|
psm->fi = rpmfiFree(psm->fi);
|
|
|
|
#ifdef NOTYET
|
|
|
|
psm->te = rpmteFree(psm->te);
|
|
|
|
#else
|
|
|
|
psm->te = NULL;
|
|
|
|
#endif
|
2003-04-09 05:42:55 +08:00
|
|
|
/*@-internalglobs@*/
|
2002-08-20 06:27:44 +08:00
|
|
|
psm->ts = rpmtsFree(psm->ts);
|
2003-04-09 05:42:55 +08:00
|
|
|
/*@=internalglobs@*/
|
2002-08-20 06:27:44 +08:00
|
|
|
|
|
|
|
(void) rpmpsmUnlink(psm, msg);
|
|
|
|
|
|
|
|
/*@-refcounttrans -usereleased@*/
|
|
|
|
/*@-boundswrite@*/
|
|
|
|
memset(psm, 0, sizeof(*psm)); /* XXX trash and burn */
|
|
|
|
/*@=boundswrite@*/
|
|
|
|
psm = _free(psm);
|
|
|
|
/*@=refcounttrans =usereleased@*/
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
/*@=nullstate@*/
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmpsm rpmpsmNew(rpmts ts, rpmte te, rpmfi fi)
|
|
|
|
{
|
|
|
|
const char * msg = "rpmpsmNew";
|
|
|
|
rpmpsm psm = xcalloc(1, sizeof(*psm));
|
|
|
|
|
|
|
|
if (ts) psm->ts = rpmtsLink(ts, msg);
|
|
|
|
#ifdef NOTYET
|
|
|
|
if (te) psm->te = rpmteLink(te, msg);
|
|
|
|
#else
|
|
|
|
/*@-assignexpose -temptrans @*/
|
|
|
|
if (te) psm->te = te;
|
|
|
|
/*@=assignexpose =temptrans @*/
|
|
|
|
#endif
|
|
|
|
if (fi) psm->fi = rpmfiLink(fi, msg);
|
|
|
|
|
|
|
|
return rpmpsmLink(psm, msg);
|
|
|
|
}
|
|
|
|
|
2003-03-19 11:00:02 +08:00
|
|
|
static void * rpmpsmThread(void * arg)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
|
2003-04-03 05:16:26 +08:00
|
|
|
/*@modifies arg, rpmGlobalMacroContext, fileSystem, internalState @*/
|
2003-03-19 11:00:02 +08:00
|
|
|
{
|
|
|
|
rpmpsm psm = arg;
|
2003-04-03 05:16:26 +08:00
|
|
|
/*@-unqualifiedtrans@*/
|
2003-03-19 11:00:02 +08:00
|
|
|
return ((void *) rpmpsmStage(psm, psm->nstage));
|
2003-04-03 05:16:26 +08:00
|
|
|
/*@=unqualifiedtrans@*/
|
2003-03-19 11:00:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmpsmNext(rpmpsm psm, pkgStage nstage)
|
2003-05-09 04:39:29 +08:00
|
|
|
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
|
2003-04-03 05:16:26 +08:00
|
|
|
/*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/
|
2003-03-19 11:00:02 +08:00
|
|
|
{
|
|
|
|
psm->nstage = nstage;
|
2003-03-20 00:05:49 +08:00
|
|
|
if (_psm_threads)
|
2003-04-07 20:05:35 +08:00
|
|
|
return rpmsqJoin( rpmsqThread(rpmpsmThread, psm) );
|
2003-03-20 00:05:49 +08:00
|
|
|
return rpmpsmStage(psm, psm->nstage);
|
2003-03-19 11:00:02 +08:00
|
|
|
}
|
|
|
|
|
2001-03-03 03:47:45 +08:00
|
|
|
/**
|
|
|
|
* @todo Packages w/o files never get a callback, hence don't get displayed
|
|
|
|
* on install with -v.
|
|
|
|
*/
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@-bounds -nullpass@*/ /* FIX: testing null annotation for fi->h */
|
2002-08-24 05:01:59 +08:00
|
|
|
rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
|
2001-02-28 06:08:53 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
const rpmts ts = psm->ts;
|
2003-01-18 01:43:04 +08:00
|
|
|
uint_32 tscolor = rpmtsColor(ts);
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmfi fi = psm->fi;
|
2001-03-03 03:47:45 +08:00
|
|
|
HGE_t hge = fi->hge;
|
2001-05-04 05:00:18 +08:00
|
|
|
HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
|
2001-03-03 01:27:30 +08:00
|
|
|
rpmRC rc = psm->rc;
|
2001-03-02 23:03:29 +08:00
|
|
|
int saveerrno;
|
2001-10-16 22:58:57 +08:00
|
|
|
int xx;
|
2001-02-28 06:08:53 +08:00
|
|
|
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2001-02-28 06:08:53 +08:00
|
|
|
switch (stage) {
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_UNKNOWN:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_INIT:
|
2001-11-12 00:17:57 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%s: %s has %d files, test = %d\n"),
|
2002-05-20 02:42:25 +08:00
|
|
|
psm->stepName, rpmteNEVR(psm->te),
|
2002-05-20 07:37:24 +08:00
|
|
|
rpmfiFC(fi), (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST));
|
2001-03-03 03:47:45 +08:00
|
|
|
|
2001-03-04 04:41:37 +08:00
|
|
|
/*
|
2004-03-27 01:27:57 +08:00
|
|
|
* When we run scripts, we pass an argument which is the number of
|
2001-03-04 04:41:37 +08:00
|
|
|
* versions of this package that will be installed when we are
|
|
|
|
* finished.
|
|
|
|
*/
|
2002-05-20 02:42:25 +08:00
|
|
|
psm->npkgs_installed = rpmdbCountPackages(rpmtsGetRdb(ts), rpmteN(psm->te));
|
2001-03-04 04:41:37 +08:00
|
|
|
if (psm->npkgs_installed < 0) {
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-06 02:22:25 +08:00
|
|
|
/* If we have a score then autorollback is enabled. If autorollback is
|
2004-03-27 01:27:57 +08:00
|
|
|
* enabled, and this is an autorollback transaction, then we may need to
|
2004-03-06 02:22:25 +08:00
|
|
|
* adjust the pkgs installed count.
|
2004-03-27 01:27:57 +08:00
|
|
|
*
|
2004-03-06 02:22:25 +08:00
|
|
|
* If all this is true, this adjustment should only be made if the PSM goal
|
2004-03-27 01:27:57 +08:00
|
|
|
* is an install. No need to make this adjustment on the erase
|
|
|
|
* component of the upgrade, or even more absurd to do this when doing a
|
2004-03-06 02:22:25 +08:00
|
|
|
* PKGSAVE.
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
if (rpmtsGetScore(ts) != NULL &&
|
2004-03-06 02:22:25 +08:00
|
|
|
rpmtsGetType(ts) == RPMTRANS_TYPE_AUTOROLLBACK &&
|
|
|
|
(psm->goal & ~(PSM_PKGSAVE|PSM_PKGERASE))) {
|
2004-03-27 01:27:57 +08:00
|
|
|
/* Get the score, if its not NULL, get the appropriate
|
2004-03-06 02:22:25 +08:00
|
|
|
* score entry.
|
|
|
|
*/
|
|
|
|
rpmtsScore score = rpmtsGetScore(ts);
|
2004-03-27 01:27:57 +08:00
|
|
|
if (score != NULL) {
|
2004-03-06 02:22:25 +08:00
|
|
|
/* OK, we got a real score so lets get the appropriate
|
|
|
|
* score entry.
|
|
|
|
*/
|
|
|
|
rpmtsScoreEntry se;
|
|
|
|
se = rpmtsScoreGetEntry(score, rpmteN(psm->te));
|
|
|
|
|
2004-03-27 01:27:57 +08:00
|
|
|
/* IF the header for the install element has been installed,
|
2004-03-06 02:22:25 +08:00
|
|
|
* but the header for the erase element has not been erased,
|
2004-03-27 01:27:57 +08:00
|
|
|
* then decrement the instance count. This is because in an
|
2004-03-06 02:22:25 +08:00
|
|
|
* autorollback, if the header was added in the initial transaction
|
2004-03-27 01:27:57 +08:00
|
|
|
* then in the case of an upgrade the instance count will be
|
2004-03-06 02:22:25 +08:00
|
|
|
* 2 instead of one when re-installing the old package, and 3 when
|
|
|
|
* erasing the new package.
|
2004-03-27 01:27:57 +08:00
|
|
|
*
|
2004-03-06 02:22:25 +08:00
|
|
|
* Another wrinkle is we only want to make this adjustement
|
|
|
|
* if the thing we are rollback was an upgrade of package. A pure
|
|
|
|
* install or erase does not need the adjustment
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
if (se && se->installed &&
|
2004-03-06 02:22:25 +08:00
|
|
|
!se->erased &&
|
|
|
|
(se->te_types & (TR_ADDED|TR_REMOVED)))
|
|
|
|
psm->npkgs_installed--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
2002-05-20 02:42:25 +08:00
|
|
|
int fc = rpmfiFC(fi);
|
2001-11-17 03:26:33 +08:00
|
|
|
|
2001-03-04 04:41:37 +08:00
|
|
|
psm->scriptArg = psm->npkgs_installed + 1;
|
2001-03-03 00:17:03 +08:00
|
|
|
|
2001-03-03 03:47:45 +08:00
|
|
|
assert(psm->mi == NULL);
|
2002-05-20 02:42:25 +08:00
|
|
|
psm->mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(psm->te), 0);
|
2003-12-27 00:34:52 +08:00
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_EPOCH, RPMMIRE_STRCMP,
|
2002-08-21 06:05:18 +08:00
|
|
|
rpmteE(psm->te));
|
2003-12-27 00:34:52 +08:00
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_VERSION, RPMMIRE_STRCMP,
|
2002-08-21 06:05:18 +08:00
|
|
|
rpmteV(psm->te));
|
2003-12-27 00:34:52 +08:00
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_RELEASE, RPMMIRE_STRCMP,
|
2002-08-21 06:05:18 +08:00
|
|
|
rpmteR(psm->te));
|
2003-01-18 01:43:04 +08:00
|
|
|
if (tscolor) {
|
2003-12-27 00:34:52 +08:00
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_ARCH, RPMMIRE_STRCMP,
|
2003-01-18 01:43:04 +08:00
|
|
|
rpmteA(psm->te));
|
2003-12-27 00:34:52 +08:00
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_OS, RPMMIRE_STRCMP,
|
2003-01-18 01:43:04 +08:00
|
|
|
rpmteO(psm->te));
|
|
|
|
}
|
2001-06-15 12:56:33 +08:00
|
|
|
|
2003-01-18 01:43:04 +08:00
|
|
|
while ((psm->oh = rpmdbNextIterator(psm->mi)) != NULL) {
|
2001-03-03 01:27:30 +08:00
|
|
|
fi->record = rpmdbGetIteratorOffset(psm->mi);
|
2003-01-02 00:54:04 +08:00
|
|
|
psm->oh = NULL;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@loopbreak@*/ break;
|
2001-03-03 00:17:03 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
psm->mi = rpmdbFreeIterator(psm->mi);
|
2001-03-03 01:27:30 +08:00
|
|
|
rc = RPMRC_OK;
|
2001-03-03 03:47:45 +08:00
|
|
|
|
2002-03-13 00:56:17 +08:00
|
|
|
/* XXX lazy alloc here may need to be done elsewhere. */
|
|
|
|
if (fi->fstates == NULL && fc > 0) {
|
2001-11-17 03:26:33 +08:00
|
|
|
fi->fstates = xmalloc(sizeof(*fi->fstates) * fc);
|
|
|
|
memset(fi->fstates, RPMFILE_STATE_NORMAL, fc);
|
2001-03-03 03:47:45 +08:00
|
|
|
}
|
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
|
2001-11-17 03:26:33 +08:00
|
|
|
if (fc <= 0) break;
|
2001-03-03 03:47:45 +08:00
|
|
|
|
|
|
|
/*
|
2003-12-30 21:14:49 +08:00
|
|
|
* Old format relocatable packages need the entire default
|
2001-03-03 03:47:45 +08:00
|
|
|
* prefix stripped to form the cpio list, while all other packages
|
|
|
|
* need the leading / stripped.
|
|
|
|
*/
|
|
|
|
{ const char * p;
|
2002-08-24 05:01:59 +08:00
|
|
|
xx = hge(fi->h, RPMTAG_DEFAULTPREFIX, NULL, (void **) &p, NULL);
|
2004-03-27 01:27:57 +08:00
|
|
|
fi->striplen = (xx ? strlen(p) + 1 : 1);
|
2001-03-03 03:47:45 +08:00
|
|
|
}
|
|
|
|
fi->mapflags =
|
2007-04-16 20:26:12 +08:00
|
|
|
CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID | (fi->mapflags & CPIO_SBIT_CHECK);
|
2001-03-03 03:47:45 +08:00
|
|
|
|
|
|
|
if (headerIsEntry(fi->h, RPMTAG_ORIGBASENAMES))
|
2002-12-19 06:54:00 +08:00
|
|
|
rpmfiBuildFNames(fi->h, RPMTAG_ORIGBASENAMES, &fi->apath, NULL);
|
2001-03-03 03:47:45 +08:00
|
|
|
else
|
2002-12-19 06:54:00 +08:00
|
|
|
rpmfiBuildFNames(fi->h, RPMTAG_BASENAMES, &fi->apath, NULL);
|
2001-03-03 03:47:45 +08:00
|
|
|
|
|
|
|
if (fi->fuser == NULL)
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = hge(fi->h, RPMTAG_FILEUSERNAME, NULL,
|
2001-03-03 03:47:45 +08:00
|
|
|
(void **) &fi->fuser, NULL);
|
|
|
|
if (fi->fgroup == NULL)
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = hge(fi->h, RPMTAG_FILEGROUPNAME, NULL,
|
2001-03-03 03:47:45 +08:00
|
|
|
(void **) &fi->fgroup, NULL);
|
|
|
|
rc = RPMRC_OK;
|
2001-03-03 00:17:03 +08:00
|
|
|
}
|
2001-03-04 05:35:41 +08:00
|
|
|
if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
|
2001-03-04 04:41:37 +08:00
|
|
|
psm->scriptArg = psm->npkgs_installed - 1;
|
2001-03-03 00:17:03 +08:00
|
|
|
|
|
|
|
/* Retrieve installed header. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_RPMDB_LOAD);
|
2002-08-24 05:01:59 +08:00
|
|
|
if (rc == RPMRC_OK)
|
2002-08-20 06:27:44 +08:00
|
|
|
if (psm->te)
|
2002-07-14 03:08:51 +08:00
|
|
|
psm->te->h = headerLink(fi->h);
|
2001-03-03 00:17:03 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
2001-03-04 04:41:37 +08:00
|
|
|
/* Open output package for writing. */
|
|
|
|
{ const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL);
|
|
|
|
const char * pkgbn =
|
|
|
|
headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL);
|
|
|
|
|
|
|
|
bfmt = _free(bfmt);
|
2002-07-26 07:36:32 +08:00
|
|
|
psm->pkgURL = rpmGenPath("%{?_repackage_root}",
|
|
|
|
"%{?_repackage_dir}",
|
2001-03-04 04:41:37 +08:00
|
|
|
pkgbn);
|
|
|
|
pkgbn = _free(pkgbn);
|
|
|
|
(void) urlPath(psm->pkgURL, &psm->pkgfn);
|
|
|
|
psm->fd = Fopen(psm->pkgfn, "w.ufdio");
|
|
|
|
if (psm->fd == NULL || Ferror(psm->fd)) {
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-03-03 00:17:03 +08:00
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_PRE:
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
|
2001-03-03 03:47:45 +08:00
|
|
|
|
2002-12-19 00:18:33 +08:00
|
|
|
/* XXX insure that trigger index is opened before entering chroot. */
|
|
|
|
#ifdef NOTYET
|
2003-01-02 04:33:21 +08:00
|
|
|
{ static int oneshot = 0;
|
|
|
|
dbiIndex dbi;
|
|
|
|
if (!oneshot) {
|
|
|
|
dbi = dbiOpen(rpmtsGetRdb(ts), RPMTAG_TRIGGERNAME, 0);
|
|
|
|
oneshot++;
|
|
|
|
}
|
|
|
|
}
|
2002-12-19 00:18:33 +08:00
|
|
|
#endif
|
|
|
|
|
2001-03-04 04:41:37 +08:00
|
|
|
/* Change root directory if requested and not already done. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_CHROOT_IN);
|
2001-03-04 04:41:37 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
|
|
|
psm->scriptTag = RPMTAG_PREIN;
|
|
|
|
psm->progTag = RPMTAG_PREINPROG;
|
2001-03-04 04:45:47 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPREIN)) {
|
2001-03-04 23:34:53 +08:00
|
|
|
/* XXX FIXME: implement %triggerprein. */
|
|
|
|
}
|
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPRE)) {
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_SCRIPT);
|
2002-08-24 05:01:59 +08:00
|
|
|
if (rc != RPMRC_OK) {
|
2001-03-04 23:34:53 +08:00
|
|
|
rpmError(RPMERR_SCRIPT,
|
2001-11-12 00:17:57 +08:00
|
|
|
_("%s: %s scriptlet failed (%d), skipping %s\n"),
|
2001-03-02 23:03:29 +08:00
|
|
|
psm->stepName, tag2sln(psm->scriptTag), rc,
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmteNEVR(psm->te));
|
2001-03-04 23:34:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
2001-03-04 04:45:47 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
|
|
|
psm->scriptTag = RPMTAG_PREUN;
|
|
|
|
psm->progTag = RPMTAG_PREUNPROG;
|
|
|
|
psm->sense = RPMSENSE_TRIGGERUN;
|
|
|
|
psm->countCorrection = -1;
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERUN)) {
|
2001-03-04 23:34:53 +08:00
|
|
|
/* Run triggers in this package other package(s) set off. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_IMMED_TRIGGERS);
|
2001-03-04 23:34:53 +08:00
|
|
|
if (rc) break;
|
2003-03-07 06:50:04 +08:00
|
|
|
|
|
|
|
/* Run triggers in other package(s) this package sets off. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_TRIGGERS);
|
2003-03-07 06:50:04 +08:00
|
|
|
if (rc) break;
|
2001-03-04 23:34:53 +08:00
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPREUN))
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_SCRIPT);
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
2002-07-26 07:36:32 +08:00
|
|
|
int noArchiveSize = 0;
|
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
/* Regenerate original header. */
|
|
|
|
{ void * uh = NULL;
|
|
|
|
int_32 uht, uhc;
|
|
|
|
|
|
|
|
if (headerGetEntry(fi->h, RPMTAG_HEADERIMMUTABLE, &uht, &uh, &uhc)) {
|
|
|
|
psm->oh = headerCopyLoad(uh);
|
|
|
|
uh = hfd(uh, uht);
|
2002-02-03 06:45:41 +08:00
|
|
|
} else
|
|
|
|
if (headerGetEntry(fi->h, RPMTAG_HEADERIMAGE, &uht, &uh, &uhc))
|
|
|
|
{
|
|
|
|
HeaderIterator hi;
|
|
|
|
int_32 tag, type, count;
|
|
|
|
hPTR_t ptr;
|
|
|
|
Header oh;
|
2001-03-03 00:17:03 +08:00
|
|
|
|
2002-02-03 06:45:41 +08:00
|
|
|
/* Load the original header from the blob. */
|
|
|
|
oh = headerCopyLoad(uh);
|
|
|
|
|
|
|
|
/* XXX this is headerCopy w/o headerReload() */
|
|
|
|
psm->oh = headerNew();
|
|
|
|
|
|
|
|
/*@-branchstate@*/
|
|
|
|
for (hi = headerInitIterator(oh);
|
|
|
|
headerNextIterator(hi, &tag, &type, &ptr, &count);
|
|
|
|
ptr = headerFreeData((void *)ptr, type))
|
|
|
|
{
|
2002-07-26 07:36:32 +08:00
|
|
|
if (tag == RPMTAG_ARCHIVESIZE)
|
|
|
|
noArchiveSize = 1;
|
2002-02-03 06:45:41 +08:00
|
|
|
if (ptr) (void) headerAddEntry(psm->oh, tag, type, ptr, count);
|
|
|
|
}
|
|
|
|
hi = headerFreeIterator(hi);
|
|
|
|
/*@=branchstate@*/
|
|
|
|
|
2002-07-14 03:08:51 +08:00
|
|
|
oh = headerFree(oh);
|
2002-02-03 06:45:41 +08:00
|
|
|
uh = hfd(uh, uht);
|
|
|
|
} else
|
|
|
|
break; /* XXX shouldn't ever happen */
|
2001-07-07 04:37:42 +08:00
|
|
|
}
|
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
/* Retrieve type of payload compression. */
|
2001-05-06 03:28:32 +08:00
|
|
|
/*@-nullstate@*/ /* FIX: psm->oh may be NULL */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_RPMIO_FLAGS);
|
2001-05-06 03:28:32 +08:00
|
|
|
/*@=nullstate@*/
|
2001-03-03 00:17:03 +08:00
|
|
|
|
|
|
|
/* Write the lead section into the package. */
|
|
|
|
{ int archnum = -1;
|
|
|
|
int osnum = -1;
|
|
|
|
struct rpmlead lead;
|
|
|
|
|
|
|
|
#ifndef DYING
|
|
|
|
rpmGetArchInfo(NULL, &archnum);
|
|
|
|
rpmGetOsInfo(NULL, &osnum);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&lead, 0, sizeof(lead));
|
|
|
|
/* XXX Set package version conditioned on noDirTokens. */
|
2002-02-03 06:45:41 +08:00
|
|
|
lead.major = 3;
|
2001-03-03 00:17:03 +08:00
|
|
|
lead.minor = 0;
|
|
|
|
lead.type = RPMLEAD_BINARY;
|
|
|
|
lead.archnum = archnum;
|
|
|
|
lead.osnum = osnum;
|
|
|
|
lead.signature_type = RPMSIGTYPE_HEADERSIG;
|
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
strncpy(lead.name, rpmteNEVR(psm->te), sizeof(lead.name));
|
2001-03-03 00:17:03 +08:00
|
|
|
|
|
|
|
rc = writeLead(psm->fd, &lead);
|
2002-08-24 05:01:59 +08:00
|
|
|
if (rc != RPMRC_OK) {
|
2001-03-03 00:17:03 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s\n"),
|
|
|
|
Fstrerror(psm->fd));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the signature section into the package. */
|
2002-07-26 07:36:32 +08:00
|
|
|
/* XXX rpm-4.1 and later has archive size in signature header. */
|
|
|
|
{ Header sigh = headerRegenSigHeader(fi->h, noArchiveSize);
|
|
|
|
/* Reallocate the signature into one contiguous region. */
|
|
|
|
sigh = headerReload(sigh, RPMTAG_HEADERSIGNATURES);
|
|
|
|
if (sigh == NULL) {
|
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to reload signature header\n"));
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rc = rpmWriteSignature(psm->fd, sigh);
|
|
|
|
sigh = rpmFreeSignature(sigh);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc) break;
|
|
|
|
}
|
|
|
|
|
2002-02-03 06:45:41 +08:00
|
|
|
/* Add remove transaction id to header. */
|
2003-01-24 04:23:24 +08:00
|
|
|
if (psm->oh != NULL)
|
2002-05-18 05:08:39 +08:00
|
|
|
{ int_32 tid = rpmtsGetTid(ts);
|
2002-02-03 06:45:41 +08:00
|
|
|
xx = headerAddEntry(psm->oh, RPMTAG_REMOVETID,
|
|
|
|
RPM_INT32_TYPE, &tid, 1);
|
|
|
|
}
|
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
/* Write the metadata section into the package. */
|
|
|
|
rc = headerWrite(psm->fd, psm->oh, HEADER_MAGIC_YES);
|
|
|
|
if (rc) break;
|
2001-03-02 23:03:29 +08:00
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_PROCESS:
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
|
2001-03-04 04:41:37 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
|
|
|
|
|
|
|
|
/* XXX Synthesize callbacks for packages with no files. */
|
|
|
|
if (rpmfiFC(fi) <= 0) {
|
|
|
|
void * ptr;
|
|
|
|
ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_START, 0, 100);
|
|
|
|
ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, 100, 100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
/* Retrieve type of payload compression. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_RPMIO_FLAGS);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
if (rpmteFd(fi->te) == NULL) { /* XXX can't happen */
|
2001-05-04 05:00:18 +08:00
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-17 03:26:33 +08:00
|
|
|
|
2001-10-31 02:00:21 +08:00
|
|
|
/*@-nullpass@*/ /* LCL: fi->fd != NULL here. */
|
2002-05-20 02:42:25 +08:00
|
|
|
psm->cfd = Fdopen(fdDup(Fileno(rpmteFd(fi->te))), psm->rpmio_flags);
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@=nullpass@*/
|
|
|
|
if (psm->cfd == NULL) { /* XXX can't happen */
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGINSTALL, ts, fi,
|
|
|
|
psm->cfd, NULL, &psm->failedFile);
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_UNCOMPRESS),
|
|
|
|
fdstat_op(psm->cfd, FDSTAT_READ));
|
|
|
|
(void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
|
|
|
|
fdstat_op(psm->cfd, FDSTAT_DIGEST));
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = fsmTeardown(fi->fsm);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
|
|
|
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fclose(psm->cfd);
|
2001-03-02 23:03:29 +08:00
|
|
|
psm->cfd = NULL;
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@-mods@*/
|
2001-03-02 23:03:29 +08:00
|
|
|
errno = saveerrno; /* XXX FIXME: Fclose with libio destroys errno */
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@=mods@*/
|
2001-03-03 01:27:30 +08:00
|
|
|
|
|
|
|
if (!rc)
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_COMMIT);
|
2001-03-03 01:27:30 +08:00
|
|
|
|
2002-08-05 00:55:55 +08:00
|
|
|
/* XXX make sure progress is closed out */
|
|
|
|
psm->what = RPMCALLBACK_INST_PROGRESS;
|
|
|
|
psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
|
|
|
|
psm->total = psm->amount;
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_NOTIFY);
|
2002-08-05 00:55:55 +08:00
|
|
|
|
2001-03-03 01:27:30 +08:00
|
|
|
if (rc) {
|
|
|
|
rpmError(RPMERR_CPIO,
|
|
|
|
_("unpacking of archive failed%s%s: %s\n"),
|
|
|
|
(psm->failedFile != NULL ? _(" on file ") : ""),
|
|
|
|
(psm->failedFile != NULL ? psm->failedFile : ""),
|
|
|
|
cpioStrerror(rc));
|
|
|
|
rc = RPMRC_FAIL;
|
2002-04-09 04:09:40 +08:00
|
|
|
|
|
|
|
/* XXX notify callback on error. */
|
|
|
|
psm->what = RPMCALLBACK_UNPACK_ERROR;
|
|
|
|
psm->amount = 0;
|
|
|
|
psm->total = 0;
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_NOTIFY);
|
2002-04-09 04:09:40 +08:00
|
|
|
|
2001-03-03 01:27:30 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
2002-05-20 02:42:25 +08:00
|
|
|
int fc = rpmfiFC(fi);
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
|
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY) break;
|
2001-11-17 03:26:33 +08:00
|
|
|
if (fc <= 0) break;
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2001-03-04 05:35:41 +08:00
|
|
|
psm->what = RPMCALLBACK_UNINST_START;
|
2001-11-17 03:26:33 +08:00
|
|
|
psm->amount = fc; /* XXX W2DO? looks wrong. */
|
|
|
|
psm->total = fc;
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_NOTIFY);
|
2001-03-02 16:28:18 +08:00
|
|
|
|
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGERASE, ts, fi,
|
|
|
|
NULL, NULL, &psm->failedFile);
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = fsmTeardown(fi->fsm);
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2001-03-04 05:35:41 +08:00
|
|
|
psm->what = RPMCALLBACK_UNINST_STOP;
|
|
|
|
psm->amount = 0; /* XXX W2DO? looks wrong. */
|
2001-11-17 03:26:33 +08:00
|
|
|
psm->total = fc;
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_NOTIFY);
|
2001-03-04 05:35:41 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
|
|
|
fileAction * actions = fi->actions;
|
|
|
|
fileAction action = fi->action;
|
|
|
|
|
|
|
|
fi->action = FA_COPYOUT;
|
|
|
|
fi->actions = NULL;
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (psm->fd == NULL) { /* XXX can't happen */
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
2002-04-12 00:55:19 +08:00
|
|
|
/*@-nullpass@*/ /* FIX: fdDup mey return NULL. */
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fflush(psm->fd);
|
2001-03-02 23:03:29 +08:00
|
|
|
psm->cfd = Fdopen(fdDup(Fileno(psm->fd)), psm->rpmio_flags);
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@=nullpass@*/
|
|
|
|
if (psm->cfd == NULL) { /* XXX can't happen */
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2001-06-26 04:01:42 +08:00
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, psm->cfd,
|
|
|
|
NULL, &psm->failedFile);
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_COMPRESS),
|
|
|
|
fdstat_op(psm->cfd, FDSTAT_WRITE));
|
|
|
|
(void) rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST),
|
|
|
|
fdstat_op(psm->cfd, FDSTAT_DIGEST));
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = fsmTeardown(fi->fsm);
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fclose(psm->cfd);
|
2001-03-02 23:03:29 +08:00
|
|
|
psm->cfd = NULL;
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@-mods@*/
|
2001-03-02 23:03:29 +08:00
|
|
|
errno = saveerrno;
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@=mods@*/
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2002-08-05 00:55:55 +08:00
|
|
|
/* XXX make sure progress is closed out */
|
|
|
|
psm->what = RPMCALLBACK_INST_PROGRESS;
|
|
|
|
psm->amount = (fi->archiveSize ? fi->archiveSize : 100);
|
|
|
|
psm->total = psm->amount;
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_NOTIFY);
|
2002-08-05 00:55:55 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
fi->action = action;
|
|
|
|
fi->actions = actions;
|
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_POST:
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
|
2001-03-04 04:41:37 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
2001-08-03 13:04:13 +08:00
|
|
|
int_32 installTime = (int_32) time(NULL);
|
2002-05-20 02:42:25 +08:00
|
|
|
int fc = rpmfiFC(fi);
|
2001-03-03 00:17:03 +08:00
|
|
|
|
2001-10-19 00:39:54 +08:00
|
|
|
if (fi->h == NULL) break; /* XXX can't happen */
|
2001-11-17 03:26:33 +08:00
|
|
|
if (fi->fstates != NULL && fc > 0)
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE,
|
2001-11-17 03:26:33 +08:00
|
|
|
fi->fstates, fc);
|
2001-03-03 00:17:03 +08:00
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
|
2001-03-03 00:17:03 +08:00
|
|
|
&installTime, 1);
|
|
|
|
|
2003-01-02 04:33:21 +08:00
|
|
|
xx = headerAddEntry(fi->h, RPMTAG_INSTALLCOLOR, RPM_INT32_TYPE,
|
|
|
|
&tscolor, 1);
|
|
|
|
|
2001-03-04 23:34:53 +08:00
|
|
|
/*
|
|
|
|
* If this package has already been installed, remove it from
|
|
|
|
* the database before adding the new one.
|
|
|
|
*/
|
2002-05-20 07:37:24 +08:00
|
|
|
if (fi->record && !(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY)) {
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_RPMDB_REMOVE);
|
2001-03-04 23:34:53 +08:00
|
|
|
if (rc) break;
|
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_RPMDB_ADD);
|
2001-03-02 16:28:18 +08:00
|
|
|
if (rc) break;
|
|
|
|
|
2001-03-04 23:34:53 +08:00
|
|
|
psm->scriptTag = RPMTAG_POSTIN;
|
|
|
|
psm->progTag = RPMTAG_POSTINPROG;
|
|
|
|
psm->sense = RPMSENSE_TRIGGERIN;
|
|
|
|
psm->countCorrection = 0;
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOST)) {
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_SCRIPT);
|
2001-03-04 23:34:53 +08:00
|
|
|
if (rc) break;
|
|
|
|
}
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERIN)) {
|
2001-03-04 23:34:53 +08:00
|
|
|
/* Run triggers in other package(s) this package sets off. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_TRIGGERS);
|
2001-03-04 23:34:53 +08:00
|
|
|
if (rc) break;
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2001-03-04 23:34:53 +08:00
|
|
|
/* Run triggers in this package other package(s) set off. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_IMMED_TRIGGERS);
|
2001-03-04 23:34:53 +08:00
|
|
|
if (rc) break;
|
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
|
2001-03-04 23:34:53 +08:00
|
|
|
rc = markReplacedFiles(psm);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
2001-03-04 23:34:53 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->scriptTag = RPMTAG_POSTUN;
|
|
|
|
psm->progTag = RPMTAG_POSTUNPROG;
|
|
|
|
psm->sense = RPMSENSE_TRIGGERPOSTUN;
|
|
|
|
psm->countCorrection = -1;
|
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOPOSTUN)) {
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_SCRIPT);
|
2004-05-04 14:04:23 +08:00
|
|
|
if (rc) break;
|
2001-03-04 23:34:53 +08:00
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERPOSTUN)) {
|
2001-03-04 23:34:53 +08:00
|
|
|
/* Run triggers in other package(s) this package sets off. */
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_TRIGGERS);
|
2001-03-04 23:34:53 +08:00
|
|
|
if (rc) break;
|
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_RPMDB_REMOVE);
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
2001-03-03 01:27:30 +08:00
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
|
|
|
}
|
2001-03-04 04:41:37 +08:00
|
|
|
|
|
|
|
/* Restore root directory if changed. */
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_CHROOT_OUT);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_UNDO:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_FINI:
|
2001-03-04 04:41:37 +08:00
|
|
|
/* Restore root directory if changed. */
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_CHROOT_OUT);
|
2001-03-04 04:41:37 +08:00
|
|
|
|
2003-01-24 04:23:24 +08:00
|
|
|
if (psm->fd != NULL) {
|
2001-03-02 23:03:29 +08:00
|
|
|
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fclose(psm->fd);
|
2001-03-02 23:03:29 +08:00
|
|
|
psm->fd = NULL;
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@-mods@*/
|
2001-03-02 23:03:29 +08:00
|
|
|
errno = saveerrno;
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@=mods@*/
|
2001-03-02 23:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
2002-08-05 00:55:55 +08:00
|
|
|
if (!rc && ts && ts->notify == NULL) {
|
2001-05-06 03:28:32 +08:00
|
|
|
rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"),
|
|
|
|
(psm->pkgURL ? psm->pkgURL : "???"));
|
2001-06-26 04:01:42 +08:00
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
}
|
|
|
|
|
2001-08-28 02:39:17 +08:00
|
|
|
if (rc) {
|
|
|
|
if (psm->failedFile)
|
|
|
|
rpmError(RPMERR_CPIO,
|
|
|
|
_("%s failed on file %s: %s\n"),
|
|
|
|
psm->stepName, psm->failedFile, cpioStrerror(rc));
|
|
|
|
else
|
|
|
|
rpmError(RPMERR_CPIO, _("%s failed: %s\n"),
|
|
|
|
psm->stepName, cpioStrerror(rc));
|
2002-04-09 04:09:40 +08:00
|
|
|
|
|
|
|
/* XXX notify callback on error. */
|
|
|
|
psm->what = RPMCALLBACK_CPIO_ERROR;
|
|
|
|
psm->amount = 0;
|
|
|
|
psm->total = 0;
|
2002-04-12 00:55:19 +08:00
|
|
|
/*@-nullstate@*/ /* FIX: psm->fd may be NULL. */
|
2003-03-19 11:00:02 +08:00
|
|
|
xx = rpmpsmNext(psm, PSM_NOTIFY);
|
2002-04-12 00:55:19 +08:00
|
|
|
/*@=nullstate@*/
|
2001-08-28 02:39:17 +08:00
|
|
|
}
|
|
|
|
|
2003-01-24 04:23:24 +08:00
|
|
|
/*@-branchstate@*/
|
2002-05-20 07:37:24 +08:00
|
|
|
if (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE) {
|
2003-01-24 04:23:24 +08:00
|
|
|
if (psm->te != NULL)
|
|
|
|
if (psm->te->h != NULL)
|
2002-07-14 03:08:51 +08:00
|
|
|
psm->te->h = headerFree(psm->te->h);
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fi->h != NULL)
|
2002-07-14 03:08:51 +08:00
|
|
|
fi->h = headerFree(fi->h);
|
2002-05-20 07:37:24 +08:00
|
|
|
}
|
2003-01-24 04:23:24 +08:00
|
|
|
/*@=branchstate@*/
|
2002-07-14 03:08:51 +08:00
|
|
|
psm->oh = headerFree(psm->oh);
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->pkgURL = _free(psm->pkgURL);
|
|
|
|
psm->rpmio_flags = _free(psm->rpmio_flags);
|
|
|
|
psm->failedFile = _free(psm->failedFile);
|
2001-03-03 03:47:45 +08:00
|
|
|
|
|
|
|
fi->fgroup = hfd(fi->fgroup, -1);
|
|
|
|
fi->fuser = hfd(fi->fuser, -1);
|
|
|
|
fi->apath = _free(fi->apath);
|
|
|
|
fi->fstates = _free(fi->fstates);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
|
|
|
|
case PSM_PKGINSTALL:
|
|
|
|
case PSM_PKGERASE:
|
2001-03-03 03:47:45 +08:00
|
|
|
case PSM_PKGSAVE:
|
|
|
|
psm->goal = stage;
|
|
|
|
psm->rc = RPMRC_OK;
|
|
|
|
psm->stepName = pkgStageString(stage);
|
|
|
|
|
2003-03-19 11:00:02 +08:00
|
|
|
rc = rpmpsmNext(psm, PSM_INIT);
|
|
|
|
if (!rc) rc = rpmpsmNext(psm, PSM_PRE);
|
|
|
|
if (!rc) rc = rpmpsmNext(psm, PSM_PROCESS);
|
|
|
|
if (!rc) rc = rpmpsmNext(psm, PSM_POST);
|
|
|
|
xx = rpmpsmNext(psm, PSM_FINI);
|
2001-03-02 16:28:18 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_PKGCOMMIT:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_CREATE:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_NOTIFY:
|
2002-05-20 07:37:24 +08:00
|
|
|
{ void * ptr;
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@-nullpass@*/ /* FIX: psm->te may be NULL */
|
2002-05-20 07:37:24 +08:00
|
|
|
ptr = rpmtsNotify(ts, psm->te, psm->what, psm->amount, psm->total);
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@-nullpass@*/
|
2002-05-20 07:37:24 +08:00
|
|
|
} break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_DESTROY:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_COMMIT:
|
2002-05-20 07:37:24 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_PKGCOMMIT)) break;
|
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY) break;
|
2001-03-04 23:34:53 +08:00
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGCOMMIT, ts, fi,
|
|
|
|
NULL, NULL, &psm->failedFile);
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = fsmTeardown(fi->fsm);
|
2001-03-02 00:01:16 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
case PSM_CHROOT_IN:
|
2002-05-20 07:37:24 +08:00
|
|
|
{ const char * rootDir = rpmtsRootDir(ts);
|
2001-02-28 23:49:23 +08:00
|
|
|
/* Change root directory if requested and not already done. */
|
2003-12-27 09:37:56 +08:00
|
|
|
if (rootDir != NULL && !(rootDir[0] == '/' && rootDir[1] == '\0')
|
|
|
|
&& !rpmtsChrootDone(ts) && !psm->chrootDone)
|
|
|
|
{
|
2004-08-31 23:39:37 +08:00
|
|
|
static int _pw_loaded = 0;
|
|
|
|
static int _gr_loaded = 0;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
2004-08-31 23:39:37 +08:00
|
|
|
if (!_pw_loaded) {
|
2001-02-28 23:49:23 +08:00
|
|
|
(void)getpwnam("root");
|
|
|
|
endpwent();
|
2004-08-31 23:39:37 +08:00
|
|
|
_pw_loaded++;
|
|
|
|
}
|
|
|
|
if (!_gr_loaded) {
|
|
|
|
(void)getgrnam("root");
|
|
|
|
endgrent();
|
|
|
|
_gr_loaded++;
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = chdir("/");
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@-superuser@*/
|
2004-11-11 11:58:46 +08:00
|
|
|
if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
|
|
|
|
rc = chroot(rootDir);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@=superuser@*/
|
2002-05-18 05:08:39 +08:00
|
|
|
psm->chrootDone = 1;
|
|
|
|
(void) rpmtsSetChrootDone(ts, 1);
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2002-05-17 00:55:21 +08:00
|
|
|
} break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_CHROOT_OUT:
|
|
|
|
/* Restore root directory if changed. */
|
|
|
|
if (psm->chrootDone) {
|
2004-11-11 11:58:46 +08:00
|
|
|
const char * rootDir = rpmtsRootDir(ts);
|
2002-05-24 03:42:23 +08:00
|
|
|
const char * currDir = rpmtsCurrDir(ts);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@-superuser@*/
|
2004-11-11 11:58:46 +08:00
|
|
|
if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
|
|
|
|
rc = chroot(".");
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@=superuser@*/
|
2002-05-18 05:08:39 +08:00
|
|
|
psm->chrootDone = 0;
|
|
|
|
(void) rpmtsSetChrootDone(ts, 0);
|
|
|
|
if (currDir != NULL) /* XXX can't happen */
|
|
|
|
xx = chdir(currDir);
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-10-19 09:24:21 +08:00
|
|
|
case PSM_SCRIPT: /* Run current package scriptlets. */
|
2001-02-28 23:49:23 +08:00
|
|
|
rc = runInstScript(psm);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-01 00:41:19 +08:00
|
|
|
case PSM_TRIGGERS:
|
2001-03-04 05:35:41 +08:00
|
|
|
/* Run triggers in other package(s) this package sets off. */
|
2001-03-02 00:01:16 +08:00
|
|
|
rc = runTriggers(psm);
|
2001-03-01 00:41:19 +08:00
|
|
|
break;
|
2002-01-23 08:58:47 +08:00
|
|
|
case PSM_IMMED_TRIGGERS:
|
2001-03-04 05:35:41 +08:00
|
|
|
/* Run triggers in this package other package(s) set off. */
|
2001-03-02 00:01:16 +08:00
|
|
|
rc = runImmedTriggers(psm);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_RPMIO_FLAGS:
|
|
|
|
{ const char * payload_compressor = NULL;
|
|
|
|
char * t;
|
|
|
|
|
2002-02-10 06:39:29 +08:00
|
|
|
/*@-branchstate@*/
|
2001-03-02 00:01:16 +08:00
|
|
|
if (!hge(fi->h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
|
|
|
|
(void **) &payload_compressor, NULL))
|
|
|
|
payload_compressor = "gzip";
|
2002-02-10 06:39:29 +08:00
|
|
|
/*@=branchstate@*/
|
2001-03-02 00:01:16 +08:00
|
|
|
psm->rpmio_flags = t = xmalloc(sizeof("w9.gzdio"));
|
2001-03-02 16:28:18 +08:00
|
|
|
*t = '\0';
|
|
|
|
t = stpcpy(t, ((psm->goal == PSM_PKGSAVE) ? "w9" : "r"));
|
2001-03-02 00:01:16 +08:00
|
|
|
if (!strcmp(payload_compressor, "gzip"))
|
|
|
|
t = stpcpy(t, ".gzdio");
|
|
|
|
if (!strcmp(payload_compressor, "bzip2"))
|
|
|
|
t = stpcpy(t, ".bzdio");
|
2001-03-03 01:27:30 +08:00
|
|
|
rc = RPMRC_OK;
|
2001-03-02 00:01:16 +08:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case PSM_RPMDB_LOAD:
|
2001-03-03 03:47:45 +08:00
|
|
|
assert(psm->mi == NULL);
|
2001-10-28 04:09:20 +08:00
|
|
|
psm->mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
|
2001-03-02 00:01:16 +08:00
|
|
|
&fi->record, sizeof(fi->record));
|
|
|
|
|
2001-03-03 03:47:45 +08:00
|
|
|
fi->h = rpmdbNextIterator(psm->mi);
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fi->h != NULL)
|
2002-07-14 03:08:51 +08:00
|
|
|
fi->h = headerLink(fi->h);
|
2002-08-03 05:52:01 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
psm->mi = rpmdbFreeIterator(psm->mi);
|
2003-01-24 04:23:24 +08:00
|
|
|
rc = (fi->h != NULL ? RPMRC_OK : RPMRC_FAIL);
|
2001-03-03 03:47:45 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_RPMDB_ADD:
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
|
2002-08-03 05:52:01 +08:00
|
|
|
if (fi->h == NULL) break; /* XXX can't happen */
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
|
2002-08-06 09:41:44 +08:00
|
|
|
if (!(rpmtsVSFlags(ts) & RPMVSF_NOHDRCHK))
|
2002-08-03 05:52:01 +08:00
|
|
|
rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
|
|
|
|
ts, headerCheck);
|
|
|
|
else
|
|
|
|
rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->h,
|
|
|
|
NULL, NULL);
|
2004-03-06 02:22:25 +08:00
|
|
|
|
|
|
|
/* Set the database instance so consumers (i.e. rpmtsRun())
|
|
|
|
* can add this to a rollback transaction.
|
|
|
|
*/
|
|
|
|
rpmteSetDBInstance(psm->te, myinstall_instance);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the score exists and this is not a rollback or autorollback
|
|
|
|
* then lets check off installed for this package.
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
if (rpmtsGetScore(ts) != NULL &&
|
|
|
|
rpmtsGetType(ts) != RPMTRANS_TYPE_ROLLBACK &&
|
|
|
|
rpmtsGetType(ts) != RPMTRANS_TYPE_AUTOROLLBACK)
|
|
|
|
{
|
|
|
|
/* Get the score, if its not NULL, get the appropriate
|
|
|
|
* score entry.
|
|
|
|
*/
|
|
|
|
rpmtsScore score = rpmtsGetScore(ts);
|
|
|
|
if (score != NULL) {
|
|
|
|
rpmtsScoreEntry se;
|
2004-03-06 02:22:25 +08:00
|
|
|
/* OK, we got a real score so lets get the appropriate
|
|
|
|
* score entry.
|
|
|
|
*/
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
2007-07-11 20:13:47 +08:00
|
|
|
_("Attempting to mark %s as installed in score board(%p).\n"),
|
|
|
|
rpmteN(psm->te), score);
|
2004-03-06 02:22:25 +08:00
|
|
|
se = rpmtsScoreGetEntry(score, rpmteN(psm->te));
|
2004-03-27 01:27:57 +08:00
|
|
|
if (se != NULL) se->installed = 1;
|
2004-03-06 02:22:25 +08:00
|
|
|
}
|
|
|
|
}
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBADD), 0);
|
2001-03-02 00:01:16 +08:00
|
|
|
break;
|
|
|
|
case PSM_RPMDB_REMOVE:
|
2002-05-20 07:37:24 +08:00
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break;
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
|
2002-08-03 05:52:01 +08:00
|
|
|
rc = rpmdbRemove(rpmtsGetRdb(ts), rpmtsGetTid(ts), fi->record,
|
|
|
|
NULL, NULL);
|
2004-03-06 02:22:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the score exists and this is not a rollback or autorollback
|
|
|
|
* then lets check off erased for this package.
|
|
|
|
*/
|
2004-03-27 01:27:57 +08:00
|
|
|
if (rpmtsGetScore(ts) != NULL &&
|
|
|
|
rpmtsGetType(ts) != RPMTRANS_TYPE_ROLLBACK &&
|
|
|
|
rpmtsGetType(ts) != RPMTRANS_TYPE_AUTOROLLBACK)
|
|
|
|
{
|
2004-03-06 02:22:25 +08:00
|
|
|
/* Get the score, if its not NULL, get the appropriate
|
|
|
|
* score entry.
|
|
|
|
*/
|
|
|
|
rpmtsScore score = rpmtsGetScore(ts);
|
2004-03-27 01:27:57 +08:00
|
|
|
|
|
|
|
if (score != NULL) { /* XXX: Can't happen */
|
|
|
|
rpmtsScoreEntry se;
|
2004-03-06 02:22:25 +08:00
|
|
|
/* OK, we got a real score so lets get the appropriate
|
|
|
|
* score entry.
|
|
|
|
*/
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
2007-07-11 20:13:47 +08:00
|
|
|
_("Attempting to mark %s as erased in score board(%p).\n"),
|
|
|
|
rpmteN(psm->te), score);
|
2004-03-06 02:22:25 +08:00
|
|
|
se = rpmtsScoreGetEntry(score, rpmteN(psm->te));
|
2004-03-27 01:27:57 +08:00
|
|
|
if (se != NULL) se->erased = 1;
|
2004-03-06 02:22:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-09 05:42:55 +08:00
|
|
|
(void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DBREMOVE), 0);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2002-02-10 06:39:29 +08:00
|
|
|
/*@i@*/ }
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2001-02-28 06:08:53 +08:00
|
|
|
|
2001-05-06 03:28:32 +08:00
|
|
|
/*@-nullstate@*/ /* FIX: psm->oh and psm->fi->h may be NULL. */
|
2001-02-28 06:08:53 +08:00
|
|
|
return rc;
|
2001-05-06 03:28:32 +08:00
|
|
|
/*@=nullstate@*/
|
2001-02-28 06:08:53 +08:00
|
|
|
}
|
2002-08-20 06:27:44 +08:00
|
|
|
/*@=bounds =nullpass@*/
|