2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup rpmtrans payload
|
|
|
|
* \file lib/uninstall.c
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-01-18 00:20:18 +08:00
|
|
|
|
1999-07-14 05:37:57 +08:00
|
|
|
#include <rpmlib.h>
|
1999-11-01 05:38:21 +08:00
|
|
|
#include <rpmurl.h>
|
2000-01-11 23:40:11 +08:00
|
|
|
#include <rpmmacro.h> /* XXX for rpmExpand */
|
1996-01-06 02:12:55 +08:00
|
|
|
|
2000-04-09 03:28:08 +08:00
|
|
|
#include "depends.h" /* XXX for headerMatchesDepFlags */
|
1996-01-09 03:19:53 +08:00
|
|
|
#include "install.h"
|
2000-04-09 03:28:08 +08:00
|
|
|
#include "misc.h" /* XXX for makeTempFile, doputenv */
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
|
2000-10-28 05:45:14 +08:00
|
|
|
/*@access Header@*/ /* XXX compared with NULL */
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin";
|
1996-03-01 09:59:03 +08:00
|
|
|
|
2000-01-25 00:11:16 +08:00
|
|
|
#define SUFFIX_RPMSAVE ".rpmsave"
|
|
|
|
|
2000-12-20 01:43:56 +08:00
|
|
|
/**
|
|
|
|
* Return scriptlet name from tag.
|
|
|
|
* @param tag scriptlet tag
|
|
|
|
* @return name of scriptlet
|
|
|
|
*/
|
|
|
|
static const char * tag2sln(int tag)
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2000-08-23 21:11:53 +08:00
|
|
|
/**
|
|
|
|
* Remove (or rename) file according to file disposition.
|
|
|
|
* @param file file
|
2000-08-30 06:04:33 +08:00
|
|
|
* @param fileAttrs file attributes (from package header)
|
2000-08-23 21:11:53 +08:00
|
|
|
* @param mode file type
|
|
|
|
* @param action file disposition
|
|
|
|
* @return
|
|
|
|
*/
|
2000-08-30 06:04:33 +08:00
|
|
|
static int removeFile(const char * file, rpmfileAttrs fileAttrs, short mode,
|
1999-07-14 22:36:10 +08:00
|
|
|
enum fileActions action)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
char * newfile;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
|
|
case FA_BACKUP:
|
2000-01-25 00:11:16 +08:00
|
|
|
newfile = alloca(strlen(file) + sizeof(SUFFIX_RPMSAVE));
|
2000-03-23 23:49:50 +08:00
|
|
|
(void)stpcpy(stpcpy(newfile, file), SUFFIX_RPMSAVE);
|
2000-01-25 00:11:16 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (rename(file, newfile)) {
|
|
|
|
rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s"),
|
|
|
|
file, newfile, strerror(errno));
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FA_REMOVE:
|
|
|
|
if (S_ISDIR(mode)) {
|
2000-07-13 07:19:08 +08:00
|
|
|
/* XXX should permit %missingok for directories as well */
|
1999-07-14 22:36:10 +08:00
|
|
|
if (rmdir(file)) {
|
2000-07-13 07:19:08 +08:00
|
|
|
switch (errno) {
|
|
|
|
case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
|
|
|
|
case ENOTEMPTY:
|
1999-07-14 22:36:10 +08:00
|
|
|
rpmError(RPMERR_RMDIR,
|
|
|
|
_("cannot remove %s - directory not empty"),
|
|
|
|
file);
|
2000-07-13 07:19:08 +08:00
|
|
|
break;
|
|
|
|
default:
|
1999-07-14 22:36:10 +08:00
|
|
|
rpmError(RPMERR_RMDIR, _("rmdir of %s failed: %s"),
|
|
|
|
file, strerror(errno));
|
2000-07-13 07:19:08 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (unlink(file)) {
|
2000-08-30 06:04:33 +08:00
|
|
|
if (errno != ENOENT || !(fileAttrs & RPMFILE_MISSINGOK)) {
|
1999-07-14 22:36:10 +08:00
|
|
|
rpmError(RPMERR_UNLINK,
|
|
|
|
_("removal of %s failed: %s"),
|
|
|
|
file, strerror(errno));
|
|
|
|
}
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FA_UNKNOWN:
|
|
|
|
case FA_CREATE:
|
|
|
|
case FA_SAVE:
|
1999-08-16 03:11:40 +08:00
|
|
|
case FA_ALTNAME:
|
1999-07-14 22:36:10 +08:00
|
|
|
case FA_SKIP:
|
|
|
|
case FA_SKIPNSTATE:
|
1999-08-16 03:11:40 +08:00
|
|
|
case FA_SKIPNETSHARED:
|
2000-07-06 04:39:15 +08:00
|
|
|
case FA_SKIPMULTILIB:
|
1999-07-14 22:36:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
int removeBinaryPackage(const rpmTransactionSet ts, unsigned int offset,
|
|
|
|
Header h, const void * pkgKey, enum fileActions * actions)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2000-10-21 06:04:27 +08:00
|
|
|
rpmtransFlags transFlags = ts->transFlags;
|
1999-08-07 06:52:49 +08:00
|
|
|
const char * name, * version, * release;
|
1999-11-27 05:58:42 +08:00
|
|
|
const char ** baseNames;
|
1996-06-28 22:37:45 +08:00
|
|
|
int scriptArg;
|
1999-09-18 05:50:10 +08:00
|
|
|
int rc = 0;
|
2000-08-21 05:39:13 +08:00
|
|
|
int fileCount;
|
|
|
|
int i;
|
1996-01-06 02:12:55 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (transFlags & RPMTRANS_FLAG_JUSTDB)
|
|
|
|
transFlags |= RPMTRANS_FLAG_NOSCRIPTS;
|
1997-07-24 23:15:48 +08:00
|
|
|
|
1999-08-07 06:52:49 +08:00
|
|
|
headerNVR(h, &name, &version, &release);
|
|
|
|
|
2000-01-25 00:11:16 +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.
|
|
|
|
*/
|
2000-10-21 06:04:27 +08:00
|
|
|
if ((scriptArg = rpmdbCountPackages(ts->rpmdb, name)) < 0)
|
2000-08-21 05:39:13 +08:00
|
|
|
return 1;
|
2000-04-08 00:09:25 +08:00
|
|
|
scriptArg -= 1;
|
1996-01-06 02:12:55 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_NOTRIGGERS)) {
|
1998-07-01 02:51:25 +08:00
|
|
|
/* run triggers from this package which are keyed on installed
|
|
|
|
packages */
|
2000-10-21 06:04:27 +08:00
|
|
|
if (runImmedTriggers(ts, RPMSENSE_TRIGGERUN, h, -1))
|
2000-08-21 05:39:13 +08:00
|
|
|
return 2;
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1998-07-01 02:51:25 +08:00
|
|
|
/* run triggers which are set off by the removal of this package */
|
2000-10-21 06:04:27 +08:00
|
|
|
if (runTriggers(ts, RPMSENSE_TRIGGERUN, h, -1))
|
2000-08-21 05:39:13 +08:00
|
|
|
return 1;
|
1998-07-01 02:51:25 +08:00
|
|
|
}
|
1996-11-01 05:07:30 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_TEST)) {
|
2000-10-21 06:04:27 +08:00
|
|
|
rc = runInstScript(ts, h, RPMTAG_PREUN, RPMTAG_PREUNPROG, scriptArg,
|
|
|
|
(transFlags & RPMTRANS_FLAG_NOSCRIPTS));
|
2000-08-21 05:39:13 +08:00
|
|
|
if (rc)
|
|
|
|
return 1;
|
1996-11-01 05:07:30 +08:00
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("will remove files test = %d\n"),
|
2000-08-30 06:04:33 +08:00
|
|
|
transFlags & RPMTRANS_FLAG_TEST);
|
1999-09-18 05:50:10 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_JUSTDB) &&
|
1999-12-09 03:04:50 +08:00
|
|
|
headerGetEntry(h, RPMTAG_BASENAMES, NULL, (void **) &baseNames,
|
1997-07-24 23:15:48 +08:00
|
|
|
&fileCount)) {
|
1999-09-18 05:50:10 +08:00
|
|
|
const char ** fileMd5List;
|
|
|
|
uint_32 * fileFlagsList;
|
|
|
|
int_16 * fileModesList;
|
1999-10-09 04:30:49 +08:00
|
|
|
const char ** dirNames;
|
|
|
|
int_32 * dirIndexes;
|
2000-08-21 05:39:13 +08:00
|
|
|
int type;
|
2000-01-25 00:11:16 +08:00
|
|
|
char * fileName;
|
|
|
|
int fnmaxlen;
|
2000-10-21 06:04:27 +08:00
|
|
|
int rdlen = (ts->rootDir && !(ts->rootDir[0] == '/' && ts->rootDir[1] == '\0'))
|
|
|
|
? strlen(ts->rootDir) : 0;
|
1999-09-18 05:50:10 +08:00
|
|
|
|
1999-12-09 03:04:50 +08:00
|
|
|
headerGetEntry(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes,
|
1999-10-09 04:30:49 +08:00
|
|
|
NULL);
|
1999-12-09 03:04:50 +08:00
|
|
|
headerGetEntry(h, RPMTAG_DIRNAMES, NULL, (void **) &dirNames,
|
1999-10-09 04:30:49 +08:00
|
|
|
NULL);
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
/* Get buffer for largest possible rootDir + dirname + filename. */
|
2000-01-25 00:11:16 +08:00
|
|
|
fnmaxlen = 0;
|
|
|
|
for (i = 0; i < fileCount; i++) {
|
|
|
|
size_t fnlen;
|
1999-11-27 05:58:42 +08:00
|
|
|
fnlen = strlen(baseNames[i]) +
|
1999-10-09 04:30:49 +08:00
|
|
|
strlen(dirNames[dirIndexes[i]]);
|
2000-01-25 00:11:16 +08:00
|
|
|
if (fnlen > fnmaxlen)
|
|
|
|
fnmaxlen = fnlen;
|
|
|
|
}
|
2000-08-28 03:27:03 +08:00
|
|
|
fnmaxlen += rdlen + sizeof("/"); /* XXX one byte too many */
|
1999-10-09 04:30:49 +08:00
|
|
|
|
2000-01-25 00:11:16 +08:00
|
|
|
fileName = alloca(fnmaxlen);
|
1999-10-09 04:30:49 +08:00
|
|
|
|
2000-08-23 21:11:53 +08:00
|
|
|
if (rdlen) {
|
2000-10-21 06:04:27 +08:00
|
|
|
strcpy(fileName, ts->rootDir);
|
2000-03-23 23:49:50 +08:00
|
|
|
(void)rpmCleanPath(fileName);
|
2000-08-23 21:11:53 +08:00
|
|
|
rdlen = strlen(fileName);
|
2000-01-25 00:11:16 +08:00
|
|
|
} else
|
|
|
|
*fileName = '\0';
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMD5S, &type, (void **) &fileMd5List,
|
1996-01-09 03:19:53 +08:00
|
|
|
&fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEFLAGS, &type, (void **) &fileFlagsList,
|
1996-01-09 03:19:53 +08:00
|
|
|
&fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMODES, &type, (void **) &fileModesList,
|
1996-01-09 04:21:22 +08:00
|
|
|
&fileCount);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if (ts->notify) {
|
|
|
|
(void)ts->notify(h, RPMCALLBACK_UNINST_START, fileCount, fileCount,
|
|
|
|
pkgKey, ts->notifyData);
|
2000-08-21 05:39:13 +08:00
|
|
|
}
|
|
|
|
|
1999-09-18 05:50:10 +08:00
|
|
|
/* Traverse filelist backwards to help insure that rmdir() will work. */
|
1996-01-30 03:37:28 +08:00
|
|
|
for (i = fileCount - 1; i >= 0; i--) {
|
1999-10-09 04:30:49 +08:00
|
|
|
|
2000-01-25 00:11:16 +08:00
|
|
|
/* XXX this assumes that dirNames always starts/ends with '/' */
|
2000-08-23 21:11:53 +08:00
|
|
|
(void)stpcpy(stpcpy(fileName+rdlen, dirNames[dirIndexes[i]]), baseNames[i]);
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1999-01-05 00:44:05 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _(" file: %s action: %s\n"),
|
2000-01-25 00:11:16 +08:00
|
|
|
fileName, fileActionString(actions[i]));
|
1999-01-05 00:44:05 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_TEST)) {
|
2000-10-21 06:04:27 +08:00
|
|
|
if (ts->notify) {
|
|
|
|
(void)ts->notify(h, RPMCALLBACK_UNINST_PROGRESS,
|
|
|
|
i, actions[i], fileName, ts->notifyData);
|
2000-08-21 05:39:13 +08:00
|
|
|
}
|
2000-01-25 00:11:16 +08:00
|
|
|
removeFile(fileName, fileFlagsList[i], fileModesList[i],
|
1999-10-09 04:30:49 +08:00
|
|
|
actions[i]);
|
2000-08-21 05:39:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if (ts->notify) {
|
|
|
|
(void)ts->notify(h, RPMCALLBACK_UNINST_STOP, 0, fileCount,
|
|
|
|
pkgKey, ts->notifyData);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1999-11-27 05:58:42 +08:00
|
|
|
free(baseNames);
|
1999-10-09 04:30:49 +08:00
|
|
|
free(dirNames);
|
1996-01-09 03:19:53 +08:00
|
|
|
free(fileMd5List);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_TEST)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("running postuninstall script (if any)\n"));
|
2000-10-21 06:04:27 +08:00
|
|
|
rc = runInstScript(ts, h, RPMTAG_POSTUN, RPMTAG_POSTUNPROG,
|
|
|
|
scriptArg, (transFlags & RPMTRANS_FLAG_NOSCRIPTS));
|
2000-08-21 05:39:13 +08:00
|
|
|
/* XXX postun failures are not cause for erasure failure. */
|
1998-01-08 23:32:10 +08:00
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_NOTRIGGERS)) {
|
1999-09-18 05:50:10 +08:00
|
|
|
/* Run postun triggers which are set off by this package's removal. */
|
2000-10-21 06:04:27 +08:00
|
|
|
rc = runTriggers(ts, RPMSENSE_TRIGGERPOSTUN, h, -1);
|
2000-08-21 05:39:13 +08:00
|
|
|
if (rc)
|
|
|
|
return 2;
|
1998-04-06 01:22:28 +08:00
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_TEST))
|
2000-10-21 06:04:27 +08:00
|
|
|
rpmdbRemove(ts->rpmdb, offset);
|
1996-01-06 02:12:55 +08:00
|
|
|
|
2000-08-21 05:39:13 +08:00
|
|
|
return 0;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
2000-08-23 21:11:53 +08:00
|
|
|
/**
|
2000-10-21 06:04:27 +08:00
|
|
|
* @param ts transaction set
|
2000-08-23 21:11:53 +08:00
|
|
|
* @param h header
|
2000-12-20 01:43:56 +08:00
|
|
|
* @param sln name of scriptlet section
|
2000-08-23 21:11:53 +08:00
|
|
|
* @param progArgc
|
|
|
|
* @param progArgv
|
|
|
|
* @param script
|
|
|
|
* @param arg1
|
|
|
|
* @param arg2
|
|
|
|
* @return
|
|
|
|
*/
|
2000-10-21 06:04:27 +08:00
|
|
|
static int runScript(const rpmTransactionSet ts, Header h,
|
2000-12-20 01:43:56 +08:00
|
|
|
const char * sln,
|
2000-10-21 06:04:27 +08:00
|
|
|
int progArgc, const char ** progArgv,
|
|
|
|
const char * script, int arg1, int arg2)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
1999-09-18 05:50:10 +08:00
|
|
|
const char ** argv = NULL;
|
|
|
|
int argc = 0;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char ** prefixes = NULL;
|
1998-01-30 03:39:12 +08:00
|
|
|
int numPrefixes;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char * oldPrefix;
|
1998-01-30 03:39:12 +08:00
|
|
|
int maxPrefixLength;
|
1998-03-28 00:46:39 +08:00
|
|
|
int len;
|
1999-09-18 05:50:10 +08:00
|
|
|
char * prefixBuf = NULL;
|
1998-03-28 00:46:39 +08:00
|
|
|
pid_t child;
|
|
|
|
int status;
|
1999-09-18 05:50:10 +08:00
|
|
|
const char * fn = NULL;
|
1998-01-30 03:39:12 +08:00
|
|
|
int i;
|
1998-04-20 22:44:07 +08:00
|
|
|
int freePrefixes = 0;
|
1998-11-20 02:10:28 +08:00
|
|
|
FD_t out;
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1998-03-28 00:46:39 +08:00
|
|
|
if (!progArgv && !script)
|
1997-07-16 09:41:50 +08:00
|
|
|
return 0;
|
1998-03-28 00:46:39 +08:00
|
|
|
else if (!progArgv) {
|
|
|
|
argv = alloca(5 * sizeof(char *));
|
|
|
|
argv[0] = "/bin/sh";
|
|
|
|
argc = 1;
|
1997-10-18 02:35:53 +08:00
|
|
|
} else {
|
1998-03-28 00:46:39 +08:00
|
|
|
argv = alloca((progArgc + 4) * sizeof(char *));
|
|
|
|
memcpy(argv, progArgv, progArgc * sizeof(char *));
|
|
|
|
argc = progArgc;
|
1997-10-18 02:35:53 +08:00
|
|
|
}
|
1997-07-16 09:41:50 +08:00
|
|
|
|
1999-04-14 20:35:08 +08:00
|
|
|
if (headerGetEntry(h, RPMTAG_INSTPREFIXES, NULL, (void **) &prefixes,
|
1998-01-30 03:39:12 +08:00
|
|
|
&numPrefixes)) {
|
|
|
|
freePrefixes = 1;
|
|
|
|
} else if (headerGetEntry(h, RPMTAG_INSTALLPREFIX, NULL,
|
|
|
|
(void **) &oldPrefix,
|
1997-07-16 09:41:50 +08:00
|
|
|
NULL)) {
|
1998-01-30 03:39:12 +08:00
|
|
|
prefixes = &oldPrefix;
|
|
|
|
numPrefixes = 1;
|
|
|
|
} else {
|
|
|
|
numPrefixes = 0;
|
1997-07-16 09:41:50 +08:00
|
|
|
}
|
|
|
|
|
1998-01-30 03:39:12 +08:00
|
|
|
maxPrefixLength = 0;
|
|
|
|
for (i = 0; i < numPrefixes; i++) {
|
1998-03-28 00:46:39 +08:00
|
|
|
len = strlen(prefixes[i]);
|
|
|
|
if (len > maxPrefixLength) maxPrefixLength = len;
|
1998-01-30 03:39:12 +08:00
|
|
|
}
|
|
|
|
prefixBuf = alloca(maxPrefixLength + 50);
|
|
|
|
|
1997-07-16 09:41:50 +08:00
|
|
|
if (script) {
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd;
|
2000-12-20 01:43:56 +08:00
|
|
|
if (makeTempFile((!ts->chrootDone ? ts->rootDir : "/"), &fn, &fd)) {
|
1998-03-28 00:46:39 +08:00
|
|
|
if (freePrefixes) free(prefixes);
|
1996-01-09 03:19:53 +08:00
|
|
|
return 1;
|
1997-10-18 02:35:53 +08:00
|
|
|
}
|
1997-07-16 09:41:50 +08:00
|
|
|
|
1998-03-28 00:46:39 +08:00
|
|
|
if (rpmIsDebug() &&
|
|
|
|
(!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
|
1999-11-11 06:09:49 +08:00
|
|
|
(void)Fwrite("set -x\n", sizeof(char), 7, fd);
|
1997-07-16 09:41:50 +08:00
|
|
|
|
1999-11-11 06:09:49 +08:00
|
|
|
(void)Fwrite(script, sizeof(script[0]), strlen(script), fd);
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1997-07-16 09:41:50 +08:00
|
|
|
|
2000-12-20 01:43:56 +08:00
|
|
|
{ const char * sn = fn;
|
|
|
|
if (!ts->chrootDone &&
|
|
|
|
!(ts->rootDir[0] == '/' && ts->rootDir[1] == '\0'))
|
|
|
|
{
|
|
|
|
sn += strlen(ts->rootDir)-1;
|
|
|
|
}
|
|
|
|
argv[argc++] = sn;
|
|
|
|
}
|
|
|
|
|
1998-03-28 00:46:39 +08:00
|
|
|
if (arg1 >= 0) {
|
1999-01-07 01:33:50 +08:00
|
|
|
char *av = alloca(20);
|
|
|
|
sprintf(av, "%d", arg1);
|
|
|
|
argv[argc++] = av;
|
1998-03-28 00:46:39 +08:00
|
|
|
}
|
|
|
|
if (arg2 >= 0) {
|
1999-01-07 01:33:50 +08:00
|
|
|
char *av = alloca(20);
|
|
|
|
sprintf(av, "%d", arg2);
|
|
|
|
argv[argc++] = av;
|
1998-03-28 00:46:39 +08:00
|
|
|
}
|
1997-07-16 09:41:50 +08:00
|
|
|
}
|
|
|
|
|
1998-03-28 00:46:39 +08:00
|
|
|
argv[argc] = NULL;
|
1997-10-18 02:35:53 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if (ts->scriptFd != NULL) {
|
1997-10-18 02:35:53 +08:00
|
|
|
if (rpmIsVerbose()) {
|
2000-10-21 06:04:27 +08:00
|
|
|
out = fdDup(Fileno(ts->scriptFd));
|
1997-10-18 02:35:53 +08:00
|
|
|
} else {
|
1999-11-05 05:26:08 +08:00
|
|
|
out = Fopen("/dev/null", "w.fdio");
|
1999-11-16 07:57:18 +08:00
|
|
|
if (Ferror(out)) {
|
2000-10-21 06:04:27 +08:00
|
|
|
out = fdDup(Fileno(ts->scriptFd));
|
1999-11-16 07:57:18 +08:00
|
|
|
}
|
1997-10-18 02:35:53 +08:00
|
|
|
}
|
1998-11-20 02:10:28 +08:00
|
|
|
} else {
|
|
|
|
out = fdDup(STDOUT_FILENO);
|
1999-11-16 07:57:18 +08:00
|
|
|
out = fdLink(out, "runScript persist");
|
1997-07-16 09:41:50 +08:00
|
|
|
}
|
1997-10-18 02:35:53 +08:00
|
|
|
|
1997-07-16 09:41:50 +08:00
|
|
|
if (!(child = fork())) {
|
2000-12-20 01:43:56 +08:00
|
|
|
const char * rootDir;
|
1999-09-18 05:50:10 +08:00
|
|
|
int pipes[2];
|
|
|
|
|
|
|
|
pipes[0] = pipes[1] = 0;
|
1997-07-16 09:41:50 +08:00
|
|
|
/* make stdin inaccessible */
|
|
|
|
pipe(pipes);
|
|
|
|
close(pipes[1]);
|
1998-11-20 02:10:28 +08:00
|
|
|
dup2(pipes[0], STDIN_FILENO);
|
1997-10-18 02:35:53 +08:00
|
|
|
close(pipes[0]);
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if (ts->scriptFd != NULL) {
|
|
|
|
if (Fileno(ts->scriptFd) != STDERR_FILENO)
|
|
|
|
dup2(Fileno(ts->scriptFd), STDERR_FILENO);
|
1999-10-31 00:43:29 +08:00
|
|
|
if (Fileno(out) != STDOUT_FILENO)
|
|
|
|
dup2(Fileno(out), STDOUT_FILENO);
|
1997-10-18 02:35:53 +08:00
|
|
|
/* make sure we don't close stdin/stderr/stdout by mistake! */
|
2000-10-21 06:04:27 +08:00
|
|
|
if (Fileno(out) > STDERR_FILENO && Fileno(out) != Fileno(ts->scriptFd)) {
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose (out);
|
1999-11-16 07:57:18 +08:00
|
|
|
}
|
2000-10-21 06:04:27 +08:00
|
|
|
if (Fileno(ts->scriptFd) > STDERR_FILENO) {
|
|
|
|
Fclose (ts->scriptFd);
|
1999-11-16 07:57:18 +08:00
|
|
|
}
|
1997-10-18 02:35:53 +08:00
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
|
2000-01-11 23:22:35 +08:00
|
|
|
{ const char *ipath = rpmExpand("PATH=%{_install_script_path}", NULL);
|
|
|
|
const char *path = SCRIPT_PATH;
|
|
|
|
|
|
|
|
if (ipath && ipath[5] != '%')
|
|
|
|
path = ipath;
|
|
|
|
doputenv(path);
|
2000-12-13 04:03:45 +08:00
|
|
|
if (ipath) free((void *)ipath);
|
2000-01-11 23:22:35 +08:00
|
|
|
}
|
1998-01-30 03:39:12 +08:00
|
|
|
|
|
|
|
for (i = 0; i < numPrefixes; i++) {
|
|
|
|
sprintf(prefixBuf, "RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
|
|
|
|
doputenv(prefixBuf);
|
|
|
|
|
|
|
|
/* backwards compatibility */
|
1998-11-20 03:10:23 +08:00
|
|
|
if (i == 0) {
|
1998-01-30 03:39:12 +08:00
|
|
|
sprintf(prefixBuf, "RPM_INSTALL_PREFIX=%s", prefixes[i]);
|
|
|
|
doputenv(prefixBuf);
|
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
|
2000-12-20 01:43:56 +08:00
|
|
|
rootDir = ts->rootDir;
|
|
|
|
switch(urlIsURL(rootDir)) {
|
1999-11-01 05:38:21 +08:00
|
|
|
case URL_IS_PATH:
|
2000-12-20 01:43:56 +08:00
|
|
|
rootDir += sizeof("file://") - 1;
|
|
|
|
rootDir = strchr(rootDir, '/');
|
1999-11-01 05:38:21 +08:00
|
|
|
/*@fallthrough@*/
|
|
|
|
case URL_IS_UNKNOWN:
|
2000-12-20 01:43:56 +08:00
|
|
|
if (!ts->chrootDone && !(rootDir[0] == '/' && rootDir[1] == '\0')) {
|
|
|
|
/*@-unrecog@*/ chroot(rootDir); /*@=unrecog@*/
|
|
|
|
}
|
1999-11-01 05:38:21 +08:00
|
|
|
chdir("/");
|
|
|
|
execv(argv[0], (char *const *)argv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1997-10-18 02:35:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_exit(-1);
|
1999-09-18 05:50:10 +08:00
|
|
|
/*@notreached@*/
|
1997-07-16 09:41:50 +08:00
|
|
|
}
|
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
(void)waitpid(child, &status, 0);
|
1997-07-16 09:41:50 +08:00
|
|
|
|
1998-01-30 03:39:12 +08:00
|
|
|
if (freePrefixes) free(prefixes);
|
|
|
|
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(out); /* XXX dup'd STDOUT_FILENO */
|
1997-10-18 02:35:53 +08:00
|
|
|
|
1997-09-10 05:00:48 +08:00
|
|
|
if (script) {
|
1998-03-28 00:46:39 +08:00
|
|
|
if (!rpmIsDebug()) unlink(fn);
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)fn);
|
1997-09-10 05:00:48 +08:00
|
|
|
}
|
1997-07-16 09:41:50 +08:00
|
|
|
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
2000-07-11 10:12:49 +08:00
|
|
|
const char *n, *v, *r;
|
|
|
|
headerNVR(h, &n, &v, &r);
|
|
|
|
rpmError(RPMERR_SCRIPT,
|
2000-12-20 01:43:56 +08:00
|
|
|
_("execution of %s scriptlet from %s-%s-%s failed, exit status %d"),
|
|
|
|
sln, n, v, r, WEXITSTATUS(status));
|
1997-07-16 09:41:50 +08:00
|
|
|
return 1;
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
int runInstScript(const rpmTransactionSet ts, Header h,
|
|
|
|
int scriptTag, int progTag, int arg, int norunScripts)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
1998-03-28 00:46:39 +08:00
|
|
|
void ** programArgv;
|
|
|
|
int programArgc;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char ** argv;
|
1998-03-28 00:46:39 +08:00
|
|
|
int programType;
|
|
|
|
char * script;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (norunScripts) return 0;
|
|
|
|
|
|
|
|
/* headerGetEntry() sets the data pointer to NULL if the entry does
|
|
|
|
not exist */
|
|
|
|
headerGetEntry(h, progTag, &programType, (void **) &programArgv,
|
|
|
|
&programArgc);
|
|
|
|
headerGetEntry(h, scriptTag, NULL, (void **) &script, NULL);
|
|
|
|
|
|
|
|
if (programArgv && programType == RPM_STRING_TYPE) {
|
|
|
|
argv = alloca(sizeof(char *));
|
1999-01-07 01:33:50 +08:00
|
|
|
*argv = (const char *) programArgv;
|
1998-03-28 00:46:39 +08:00
|
|
|
} else {
|
1999-01-07 01:33:50 +08:00
|
|
|
argv = (const char **) programArgv;
|
1998-03-28 00:46:39 +08:00
|
|
|
}
|
|
|
|
|
2000-12-20 01:43:56 +08:00
|
|
|
rc = runScript(ts, h, tag2sln(scriptTag), programArgc, argv, script,
|
|
|
|
arg, -1);
|
|
|
|
headerFreeData(programArgv, programType);
|
1998-03-28 00:46:39 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2000-08-23 21:11:53 +08:00
|
|
|
/**
|
2000-10-21 06:04:27 +08:00
|
|
|
* @param ts transaction set
|
2000-08-23 21:11:53 +08:00
|
|
|
* @param sense
|
|
|
|
* @param sourceH
|
|
|
|
* @param triggeredH
|
|
|
|
* @param arg1correction
|
|
|
|
* @param arg2
|
|
|
|
* @param triggersAlreadyRun
|
|
|
|
* @return
|
|
|
|
*/
|
2000-10-21 06:04:27 +08:00
|
|
|
static int handleOneTrigger(const rpmTransactionSet ts, int sense,
|
2000-08-23 21:11:53 +08:00
|
|
|
Header sourceH, Header triggeredH,
|
|
|
|
int arg1correction, int arg2,
|
2000-10-21 06:04:27 +08:00
|
|
|
char * triggersAlreadyRun)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
1999-01-07 01:33:50 +08:00
|
|
|
const char ** triggerNames;
|
1999-09-18 05:50:10 +08:00
|
|
|
const char ** triggerEVR;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char ** triggerScripts;
|
|
|
|
const char ** triggerProgs;
|
2000-04-13 17:07:08 +08:00
|
|
|
int_32 * triggerFlags;
|
|
|
|
int_32 * triggerIndices;
|
|
|
|
const char * triggerPackageName;
|
|
|
|
const char * sourceName;
|
1998-03-28 00:46:39 +08:00
|
|
|
int numTriggers;
|
|
|
|
int rc = 0;
|
|
|
|
int i;
|
1998-07-01 02:51:25 +08:00
|
|
|
int skip;
|
1998-03-28 00:46:39 +08:00
|
|
|
|
|
|
|
if (!headerGetEntry(triggeredH, RPMTAG_TRIGGERNAME, NULL,
|
|
|
|
(void **) &triggerNames, &numTriggers)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-13 17:07:08 +08:00
|
|
|
headerNVR(sourceH, &sourceName, NULL, NULL);
|
1998-03-28 00:46:39 +08:00
|
|
|
|
|
|
|
headerGetEntry(triggeredH, RPMTAG_TRIGGERFLAGS, NULL,
|
|
|
|
(void **) &triggerFlags, NULL);
|
|
|
|
headerGetEntry(triggeredH, RPMTAG_TRIGGERVERSION, NULL,
|
1999-09-18 05:50:10 +08:00
|
|
|
(void **) &triggerEVR, NULL);
|
1998-03-28 00:46:39 +08:00
|
|
|
|
|
|
|
for (i = 0; i < numTriggers; i++) {
|
2000-03-23 23:49:50 +08:00
|
|
|
|
1998-03-28 00:46:39 +08:00
|
|
|
if (!(triggerFlags[i] & sense)) continue;
|
|
|
|
if (strcmp(triggerNames[i], sourceName)) continue;
|
1998-07-01 02:51:25 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
/* For some reason, the TRIGGERVERSION stuff includes the name of the package which the trigger is based on. We need to skip
|
1998-07-01 02:51:25 +08:00
|
|
|
over that here. I suspect that we'll change our minds on this
|
|
|
|
and remove that, so I'm going to just 'do the right thing'. */
|
|
|
|
skip = strlen(triggerNames[i]);
|
1999-09-18 05:50:10 +08:00
|
|
|
if (!strncmp(triggerEVR[i], triggerNames[i], skip) &&
|
|
|
|
(triggerEVR[i][skip] == '-'))
|
1998-07-01 02:51:25 +08:00
|
|
|
skip++;
|
|
|
|
else
|
|
|
|
skip = 0;
|
|
|
|
|
1999-07-23 01:48:31 +08:00
|
|
|
if (!headerMatchesDepFlags(sourceH, triggerNames[i],
|
1999-09-18 05:50:10 +08:00
|
|
|
triggerEVR[i] + skip, triggerFlags[i]))
|
1999-07-23 01:48:31 +08:00
|
|
|
continue;
|
1998-03-28 00:46:39 +08:00
|
|
|
|
|
|
|
headerGetEntry(triggeredH, RPMTAG_TRIGGERINDEX, NULL,
|
|
|
|
(void **) &triggerIndices, NULL);
|
|
|
|
headerGetEntry(triggeredH, RPMTAG_TRIGGERSCRIPTS, NULL,
|
|
|
|
(void **) &triggerScripts, NULL);
|
|
|
|
headerGetEntry(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, NULL,
|
|
|
|
(void **) &triggerProgs, NULL);
|
|
|
|
|
2000-04-13 17:07:08 +08:00
|
|
|
headerNVR(triggeredH, &triggerPackageName, NULL, NULL);
|
2000-03-23 23:49:50 +08:00
|
|
|
|
2000-04-08 00:09:25 +08:00
|
|
|
{ int arg1;
|
|
|
|
int index;
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if ((arg1 = rpmdbCountPackages(ts->rpmdb, triggerPackageName)) < 0) {
|
2000-04-08 00:09:25 +08:00
|
|
|
rc = 1; /* XXX W2DO? same as "execution of script failed" */
|
|
|
|
} else {
|
|
|
|
arg1 += arg1correction;
|
|
|
|
index = triggerIndices[i];
|
|
|
|
if (!triggersAlreadyRun || !triggersAlreadyRun[index]) {
|
2000-12-20 01:43:56 +08:00
|
|
|
rc = runScript(ts, triggeredH, "%trigger", 1,
|
|
|
|
triggerProgs + index, triggerScripts[index],
|
2000-10-21 06:04:27 +08:00
|
|
|
arg1, arg2);
|
2000-04-08 00:09:25 +08:00
|
|
|
if (triggersAlreadyRun) triggersAlreadyRun[index] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-09 03:28:08 +08:00
|
|
|
|
1998-03-28 00:46:39 +08:00
|
|
|
free(triggerScripts);
|
|
|
|
free(triggerProgs);
|
|
|
|
|
|
|
|
/* each target/source header pair can only result in a single
|
|
|
|
script being run */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(triggerNames);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
int runTriggers(const rpmTransactionSet ts, int sense, Header h,
|
|
|
|
int countCorrection)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2000-04-13 17:07:08 +08:00
|
|
|
const char * name;
|
1998-03-28 00:46:39 +08:00
|
|
|
int numPackage;
|
2000-04-13 17:07:08 +08:00
|
|
|
int rc = 0;
|
1998-03-28 00:46:39 +08:00
|
|
|
|
2000-04-13 17:07:08 +08:00
|
|
|
headerNVR(h, &name, NULL, NULL);
|
1998-03-28 00:46:39 +08:00
|
|
|
|
2000-10-28 05:45:14 +08:00
|
|
|
numPackage = rpmdbCountPackages(ts->rpmdb, name) + countCorrection;
|
2000-04-13 17:07:08 +08:00
|
|
|
if (numPackage < 0)
|
|
|
|
return 1;
|
1998-03-28 00:46:39 +08:00
|
|
|
|
2000-04-13 17:07:08 +08:00
|
|
|
{ Header triggeredH;
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_TRIGGERNAME, name, 0);
|
2000-04-13 17:07:08 +08:00
|
|
|
while((triggeredH = rpmdbNextIterator(mi)) != NULL) {
|
2000-10-21 06:04:27 +08:00
|
|
|
rc |= handleOneTrigger(ts, sense, h, triggeredH, 0, numPackage,
|
|
|
|
NULL);
|
2000-04-13 17:07:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbFreeIterator(mi);
|
2000-03-23 23:49:50 +08:00
|
|
|
}
|
1998-03-28 00:46:39 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
int runImmedTriggers(const rpmTransactionSet ts, int sense, Header h,
|
|
|
|
int countCorrection)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2000-04-13 17:07:08 +08:00
|
|
|
const char ** triggerNames;
|
1998-03-28 00:46:39 +08:00
|
|
|
int numTriggers;
|
|
|
|
int_32 * triggerIndices;
|
2000-04-13 17:07:08 +08:00
|
|
|
int numTriggerIndices;
|
1998-03-28 00:46:39 +08:00
|
|
|
char * triggersRun;
|
2000-04-13 17:07:08 +08:00
|
|
|
int rc = 0;
|
1998-03-28 00:46:39 +08:00
|
|
|
|
|
|
|
if (!headerGetEntry(h, RPMTAG_TRIGGERNAME, NULL, (void **) &triggerNames,
|
|
|
|
&numTriggers))
|
|
|
|
return 0;
|
|
|
|
headerGetEntry(h, RPMTAG_TRIGGERINDEX, NULL, (void **) &triggerIndices,
|
2000-04-13 17:07:08 +08:00
|
|
|
&numTriggerIndices);
|
|
|
|
triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
|
|
|
|
memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
|
1998-03-28 00:46:39 +08:00
|
|
|
|
2000-04-13 17:07:08 +08:00
|
|
|
{ Header sourceH = NULL;
|
|
|
|
int i;
|
2000-03-23 23:49:50 +08:00
|
|
|
|
2000-04-13 17:07:08 +08:00
|
|
|
for (i = 0; i < numTriggers; i++) {
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
const char * name = triggerNames[i];
|
|
|
|
|
|
|
|
if (triggersRun[triggerIndices[i]]) continue;
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, name, 0);
|
2000-04-13 17:07:08 +08:00
|
|
|
|
|
|
|
while((sourceH = rpmdbNextIterator(mi)) != NULL) {
|
2000-10-21 06:04:27 +08:00
|
|
|
rc |= handleOneTrigger(ts, sense, sourceH, h,
|
2000-04-13 17:07:08 +08:00
|
|
|
countCorrection, rpmdbGetIteratorCount(mi),
|
2000-10-21 06:04:27 +08:00
|
|
|
triggersRun);
|
2000-04-13 17:07:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbFreeIterator(mi);
|
|
|
|
}
|
2000-03-23 23:49:50 +08:00
|
|
|
}
|
1998-03-28 00:46:39 +08:00
|
|
|
return rc;
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|