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>
|
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 "ugid.h" /* XXX unameToUid() and gnameToGid() */
|
|
|
|
#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
|
|
|
|
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
|
|
|
|
2001-03-05 01:15:56 +08:00
|
|
|
int rpmVersionCompare(Header first, Header second)
|
|
|
|
{
|
|
|
|
const char * one, * two;
|
|
|
|
int_32 * epochOne, * epochTwo;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
|
|
|
|
epochOne = NULL;
|
2003-04-05 06:15:58 +08:00
|
|
|
if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo, NULL))
|
2001-03-05 01:15:56 +08:00
|
|
|
epochTwo = NULL;
|
|
|
|
|
2003-04-03 05:16:26 +08:00
|
|
|
if (epochOne != NULL && epochTwo == NULL)
|
2001-03-05 01:15:56 +08:00
|
|
|
return 1;
|
2003-04-03 05:16:26 +08:00
|
|
|
else if (epochOne == NULL && epochTwo != NULL)
|
2001-03-05 01:15:56 +08:00
|
|
|
return -1;
|
2003-04-03 05:16:26 +08:00
|
|
|
else if (epochOne != NULL && epochTwo != NULL) {
|
2002-07-03 07:54:35 +08:00
|
|
|
/*@-boundsread@*/
|
2001-03-05 01:15:56 +08:00
|
|
|
if (*epochOne < *epochTwo)
|
|
|
|
return -1;
|
|
|
|
else if (*epochOne > *epochTwo)
|
|
|
|
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
|
|
|
|
|
|
|
return rpmvercmp(one, two);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
unsigned 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
|
|
|
|
2003-01-24 04:23:24 +08:00
|
|
|
(void) rpmtsAddInstallElement(ts, h, NULL, 0, NULL);
|
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;
|
|
|
|
|
|
|
|
fi->fuids = xcalloc(sizeof(*fi->fuids), fi->fc);
|
|
|
|
fi->fgids = xcalloc(sizeof(*fi->fgids), fi->fc);
|
|
|
|
for (i = 0; i < fi->fc; i++) {
|
|
|
|
fi->fuids[i] = fi->uid;
|
|
|
|
fi->fgids[i] = fi->gid;
|
|
|
|
}
|
|
|
|
|
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@*/
|
2001-01-26 04:26:35 +08:00
|
|
|
fi->dil = (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
|
|
|
|
*/
|
|
|
|
static /*@observer@*/ const char * const 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
/*@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.
|
|
|
|
*
|
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,
|
2001-02-28 23:49:23 +08:00
|
|
|
int progArgc, const char ** progArgv,
|
|
|
|
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;
|
2001-02-28 23:49:23 +08:00
|
|
|
const char *n, *v, *r;
|
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
|
|
|
|
2003-03-18 10:41:33 +08:00
|
|
|
psm->sq.reaper = 1;
|
2002-08-20 06:27:44 +08:00
|
|
|
|
|
|
|
/* XXX FIXME: except for %verifyscript, rpmteNEVR can be used. */
|
|
|
|
xx = headerNVR(h, &n, &v, &r);
|
2002-11-14 02:18:33 +08:00
|
|
|
|
|
|
|
/* XXX bash must have functional libtermcap.so.2 */
|
|
|
|
if (!strcmp(n, "libtermcap"))
|
|
|
|
ldconfig_done = 0;
|
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
/*
|
|
|
|
* If a successor node, and ldconfig was just run, don't bother.
|
|
|
|
*/
|
|
|
|
if (ldconfig_path && progArgv && psm->unorderedSuccessor) {
|
|
|
|
if (ldconfig_done && !strcmp(progArgv[0], ldconfig_path)) {
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("%s: %s(%s-%s-%s) skipping redundant \"%s\".\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag), n, v, r,
|
|
|
|
progArgv[0]);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("%s: %s(%s-%s-%s) %ssynchronous scriptlet start\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag), n, v, r,
|
|
|
|
(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
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2001-02-28 23:49:23 +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];
|
|
|
|
|
|
|
|
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
|
|
|
|
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! */
|
2001-10-15 11:22:10 +08:00
|
|
|
if (ofdno > STDERR_FILENO && ofdno != sfdno) {
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = Fclose (out);
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-10-15 11:22:10 +08:00
|
|
|
if (sfdno > STDERR_FILENO) {
|
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
|
|
|
|
2002-05-20 07:37:24 +08:00
|
|
|
rootDir = rpmtsRootDir(ts);
|
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("/");
|
2002-08-20 06:27:44 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%s: %s(%s-%s-%s)\texecv(%s) pid %d\n"),
|
|
|
|
psm->stepName, sln, n, v, r,
|
|
|
|
argv[0], (unsigned)getpid());
|
|
|
|
unsetenv("MALLOC_CHECK_");
|
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;
|
|
|
|
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
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
(void) psmWait(psm);
|
|
|
|
|
2003-03-18 10:41:33 +08:00
|
|
|
if (psm->sq.reaped < 0) {
|
2001-02-28 23:49:23 +08:00
|
|
|
rpmError(RPMERR_SCRIPT,
|
2002-08-20 06:27:44 +08:00
|
|
|
_("%s(%s-%s-%s) scriptlet failed, waitpid(%d) rc %d: %s\n"),
|
2003-03-18 10:41:33 +08:00
|
|
|
sln, n, v, r, 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)) {
|
2002-08-20 06:27:44 +08:00
|
|
|
rpmError(RPMERR_SCRIPT,
|
|
|
|
_("%s(%s-%s-%s) scriptlet failed, exit status %d\n"),
|
2003-03-18 10:41:33 +08:00
|
|
|
sln, n, v, r, WEXITSTATUS(psm->sq.status));
|
2002-08-20 06:27:44 +08:00
|
|
|
rc = RPMRC_FAIL;
|
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 */
|
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 (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;
|
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);
|
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;
|
|
|
|
|
2002-05-18 05:08:39 +08:00
|
|
|
arg1 = rpmdbCountPackages(rpmtsGetRdb(ts), Name);
|
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,
|
|
|
|
triggerProgs + index, triggerScripts[index],
|
|
|
|
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);
|
|
|
|
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) {
|
|
|
|
rc |= handleOneTrigger(psm, sourceH, fi->h,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@observer@*/ static const char *const pkgStageString(pkgStage a)
|
|
|
|
/*@*/
|
|
|
|
{
|
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
|
|
|
/*
|
|
|
|
* When we run scripts, we pass an argument which is the number of
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
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);
|
2002-08-21 06:05:18 +08:00
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_EPOCH, RPMMIRE_DEFAULT,
|
|
|
|
rpmteE(psm->te));
|
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_VERSION, RPMMIRE_DEFAULT,
|
|
|
|
rpmteV(psm->te));
|
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT,
|
|
|
|
rpmteR(psm->te));
|
2003-01-18 01:43:04 +08:00
|
|
|
if (tscolor) {
|
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_ARCH, RPMMIRE_DEFAULT,
|
|
|
|
rpmteA(psm->te));
|
|
|
|
xx = rpmdbSetIteratorRE(psm->mi, RPMTAG_OS, RPMMIRE_DEFAULT,
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Old format relocateable packages need the entire default
|
|
|
|
* 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);
|
|
|
|
fi->striplen = (xx ? strlen(p) + 1 : 1);
|
2001-03-03 03:47:45 +08:00
|
|
|
}
|
|
|
|
fi->mapflags =
|
|
|
|
CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (fi->fuids == NULL)
|
2001-11-17 03:26:33 +08:00
|
|
|
fi->fuids = xcalloc(sizeof(*fi->fuids), fc);
|
2001-03-03 03:47:45 +08:00
|
|
|
if (fi->fgids == NULL)
|
2001-11-17 03:26:33 +08:00
|
|
|
fi->fgids = xcalloc(sizeof(*fi->fgids), fc);
|
2001-03-03 03:47:45 +08:00
|
|
|
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-05 01:15:56 +08:00
|
|
|
int i;
|
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;
|
|
|
|
}
|
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
(void) rpmfiInit(fi, 0);
|
2002-05-20 07:37:24 +08:00
|
|
|
while ((i = rpmfiNext(fi)) >= 0) {
|
2001-03-05 01:15:56 +08:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
uid = fi->uid;
|
|
|
|
gid = fi->gid;
|
|
|
|
if (fi->fuser && unameToUid(fi->fuser[i], &uid)) {
|
|
|
|
rpmMessage(RPMMESS_WARNING,
|
|
|
|
_("user %s does not exist - using root\n"),
|
|
|
|
fi->fuser[i]);
|
|
|
|
uid = 0;
|
|
|
|
/* XXX this diddles header memory. */
|
|
|
|
fi->fmodes[i] &= ~S_ISUID; /* turn off the suid bit */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fi->fgroup && gnameToGid(fi->fgroup[i], &gid)) {
|
|
|
|
rpmMessage(RPMMESS_WARNING,
|
|
|
|
_("group %s does not exist - using root\n"),
|
|
|
|
fi->fgroup[i]);
|
|
|
|
gid = 0;
|
|
|
|
/* XXX this diddles header memory. */
|
|
|
|
fi->fmodes[i] &= ~S_ISGID; /* turn off the sgid bit */
|
|
|
|
}
|
|
|
|
if (fi->fuids) fi->fuids[i] = uid;
|
|
|
|
if (fi->fgids) fi->fgids[i] = gid;
|
|
|
|
}
|
2001-03-03 01:27:30 +08:00
|
|
|
|
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);
|
2001-03-04 23:34:53 +08:00
|
|
|
/* XXX WTFO? postun failures don't cause erasure failure. */
|
|
|
|
}
|
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->fgids = _free(fi->fgids);
|
|
|
|
fi->fuids = _free(fi->fuids);
|
|
|
|
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. */
|
2002-05-24 03:42:23 +08:00
|
|
|
if (rootDir != NULL && !rpmtsChrootDone(ts) && !psm->chrootDone) {
|
2001-02-28 23:49:23 +08:00
|
|
|
static int _loaded = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This loads all of the name services libraries, in case we
|
|
|
|
* don't have access to them in the chroot().
|
|
|
|
*/
|
|
|
|
if (!_loaded) {
|
|
|
|
(void)getpwnam("root");
|
|
|
|
endpwent();
|
|
|
|
_loaded++;
|
|
|
|
}
|
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
xx = chdir("/");
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@-superuser@*/
|
2002-05-17 00:55:21 +08:00
|
|
|
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) {
|
2002-05-24 03:42:23 +08:00
|
|
|
const char * currDir = rpmtsCurrDir(ts);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@-superuser@*/
|
2001-02-28 23:49:23 +08:00
|
|
|
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);
|
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);
|
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@*/
|