19 #define _RPMEVR_INTERNAL
22 #define _RPMFI_INTERNAL
25 #define _RPMTE_INTERNAL
28 #define _RPMTS_INTERNAL
55 const char * one, * two;
56 int_32 * epochOne, * epochTwo;
66 if (*epochOne < *epochTwo)
68 else if (*epochOne > *epochTwo)
98 sharedFileInfo replaced = fi->replaced;
102 unsigned int * offsets;
106 if (!(
rpmfiFC(fi) > 0 && fi->replaced))
110 for (sfi = replaced; sfi->otherPkg; sfi++) {
111 if (prev && prev == sfi->otherPkg)
113 prev = sfi->otherPkg;
119 offsets =
alloca(num *
sizeof(*offsets));
122 for (sfi = replaced; sfi->otherPkg; sfi++) {
123 if (prev && prev == sfi->otherPkg)
125 prev = sfi->otherPkg;
126 offsets[num++] = sfi->otherPkg;
146 while (sfi->otherPkg && sfi->otherPkg == prev) {
147 assert(sfi->otherFileNum < count);
167 const char ** specFilePtr,
const char ** cookie)
171 const char * _sourcedir = NULL;
172 const char * _specdir = NULL;
173 const char * specFile = NULL;
183 memset(psm, 0,
sizeof(*psm));
184 psm->ts =
rpmtsLink(ts,
"InstallSourcePackage");
222 if (fi->te == NULL) {
227 assert(fi->h != NULL);
229 fi->te->fd =
fdLink(fd,
"installSourcePackage");
247 fi->fmapflags =
_free(fi->fmapflags);
255 for (i = 0; i < fi->fc; i++)
264 for (i = 0; i < fi->fc; i++)
270 for (i = 0; i < fi->fc; i++) {
271 const char * t = fi->apath[i];
272 t += strlen(fi->apath[i]) - 5;
273 if (!strcmp(t,
".spec"))
break;
285 "_sourcedir", _sourcedir);
298 "_specdir", _specdir);
305 int speclen = strlen(_specdir) + 2;
306 int sourcelen = strlen(_sourcedir) + 2;
309 fi->dnl = hfd(fi->dnl, -1);
312 fi->dnl =
xmalloc(fi->dc *
sizeof(*fi->dnl)
313 + fi->fc *
sizeof(*fi->dil)
314 + speclen + sourcelen);
316 fi->dil = (
int *)(fi->dnl + fi->dc);
318 memset(fi->dil, 0, fi->fc *
sizeof(*fi->dil));
321 fi->dnl[0] = t = (
char *)(fi->dil + fi->fc);
322 fi->dnl[1] = t =
stpcpy(
stpcpy(t, _sourcedir),
"/") + 1;
326 t =
xmalloc(speclen + strlen(fi->bnl[i]) + 1);
346 if (specFilePtr && specFile && rpmrc ==
RPMRC_OK)
347 *specFilePtr = specFile;
349 specFile =
_free(specFile);
351 _specdir =
_free(_specdir);
352 _sourcedir =
_free(_sourcedir);
362 if (fi->te->fd != NULL)
363 (void)
Fclose(fi->te->fd);
379 static char *
SCRIPT_PATH =
"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin";
402 return "%unknownscript";
446 D_(
"%s: waitpid(%d) rc %d status %x secs %u.%03u\n"),
449 (
unsigned)msecs/1000, (
unsigned)msecs%1000);
466 int progArgc,
const char **progArgv,
467 const char *script,
int arg1,
int arg2)
474 const char *n, *v, *r;
491 pwdFdno = open(
".", O_RDONLY, 0);
495 rootFdno = open(
"/", O_RDONLY, 0);
501 if (rootDir != NULL && strcmp(rootDir,
"/") && *rootDir ==
'/') {
512 rpmluaPushTable(lua,
"arg");
514 rpmluavSetListMode(var, 1);
517 for (i = 0; i < progArgc && progArgv[i]; i++) {
518 rpmluavSetValue(var, RPMLUAV_STRING, progArgv[i]);
519 rpmluaSetVar(lua, var);
523 rpmluavSetValueNum(var, arg1);
524 rpmluaSetVar(lua, var);
527 rpmluavSetValueNum(var, arg2);
528 rpmluaSetVar(lua, var);
532 var = rpmluavFree(var);
538 xx =
snprintf(buf, BUFSIZ,
"%s(%s-%s-%s)", sln, n, v, r);
539 xx = rpmluaRunScript(lua, script, buf);
544 *ssp |= (xx & 0xffff);
549 rpmluaDelVar(lua,
"arg");
554 xx = fchdir(rootFdno);
556 if (rootDir != NULL && strcmp(rootDir,
"/") && *rootDir ==
'/') {
561 xx = fchdir(pwdFdno);
563 xx = fchdir(pwdFdno);
565 xx = close(rootFdno);
599 int progArgc,
const char ** progArgv,
600 const char * script,
int arg1,
int arg2)
610 const char ** argv = NULL;
612 const char ** prefixes = NULL;
615 const char * oldPrefix;
618 char * prefixBuf = NULL;
619 const char * fn = NULL;
622 int freePrefixes = 0;
626 const char *n, *v, *r, *a;
634 if (progArgv == NULL && script == NULL)
641 if (progArgv && strcmp(progArgv[0],
"<lua>") == 0) {
644 D_(
"%s: %s(%s-%s-%s.%s) running <lua> scriptlet.\n"),
646 return runLuaScript(psm, h, sln, progArgc, progArgv,
666 if (ldconfig_done && !strcmp(progArgv[0], ldconfig_path)) {
668 D_(
"%s: %s(%s-%s-%s.%s) skipping redundant \"%s\".\n"),
676 D_(
"%s: %s(%s-%s-%s.%s) %ssynchronous scriptlet start\n"),
681 argv =
alloca(5 *
sizeof(*argv));
686 argv =
alloca((progArgc + 4) *
sizeof(*argv));
687 memcpy(argv, progArgv, progArgc *
sizeof(*argv));
689 ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path)
695 if ((a != NULL && a[0] ==
'i' && a[1] !=
'\0' && a[2] ==
'8' && a[3] ==
'6')
696 && strcmp(argv[0],
"/sbin/ldconfig"))
698 const char * fmt =
rpmGetPath(
"%{?_autorelocate_path}", NULL);
707 if (newPath != NULL && *newPath !=
'\0'
708 && strlen(newPath) >= (
sizeof(
"/emul/i386")-1)
709 && newPath[0] ==
'/' && newPath[1] ==
'e' && newPath[2] ==
'm'
710 && newPath[3] ==
'u' && newPath[4] ==
'l' && newPath[5] ==
'/'
711 && newPath[6] ==
'i' && newPath[8] ==
'8' && newPath[9] ==
'6')
718 t =
alloca(strlen(newPath) + strlen(argv[0]) + 1);
721 newPath =
_free(newPath);
729 prefixes = &oldPrefix;
736 if (prefixes != NULL)
737 for (i = 0; i < numPrefixes; i++) {
738 len = strlen(prefixes[i]);
739 if (len > maxPrefixLength) maxPrefixLength = len;
741 prefixBuf =
alloca(maxPrefixLength + 50);
749 if (prefixes != NULL && freePrefixes) free(prefixes);
755 (!strcmp(argv[0],
"/bin/sh") || !strcmp(argv[0],
"/bin/bash")))
757 static const char set_x[] =
"set -x\n";
758 xx =
Fwrite(set_x,
sizeof(set_x[0]),
sizeof(set_x)-1, fd);
761 if (ldconfig_path && strstr(script, ldconfig_path) != NULL)
764 xx =
Fwrite(script,
sizeof(script[0]), strlen(script), fd);
767 {
const char * sn = fn;
769 !(rootDir[0] ==
'/' && rootDir[1] ==
'\0'))
771 sn += strlen(rootDir)-1;
778 sprintf(av,
"%d", arg1);
783 sprintf(av,
"%d", arg2);
791 if (scriptFd != NULL) {
795 out =
Fopen(
"/dev/null",
"w.fdio");
801 out =
fdDup(STDOUT_FILENO);
808 const char * rootDir;
813 pipes[0] = pipes[1] = 0;
816 xx = close(pipes[1]);
817 xx = dup2(pipes[0], STDIN_FILENO);
818 xx = close(pipes[0]);
821 for (fdno = 3; fdno < 100; fdno++) {
822 flag = fcntl(fdno, F_GETFD);
823 if (flag == -1 || (flag & FD_CLOEXEC))
825 xx = fcntl(fdno, F_SETFD, FD_CLOEXEC);
829 if (scriptFd != NULL) {
830 int sfdno =
Fileno(scriptFd);
832 if (sfdno != STDERR_FILENO)
833 xx = dup2(sfdno, STDERR_FILENO);
834 if (ofdno != STDOUT_FILENO)
835 xx = dup2(ofdno, STDOUT_FILENO);
837 if (ofdno > STDERR_FILENO && ofdno != sfdno)
839 if (sfdno > STDERR_FILENO)
848 {
const char *ipath =
rpmExpand(
"PATH=%{_install_script_path}", NULL);
851 if (ipath && ipath[5] !=
'%')
856 ipath =
_free(ipath);
860 if (prefixes != NULL)
861 for (i = 0; i < numPrefixes; i++) {
862 sprintf(prefixBuf,
"RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
867 sprintf(prefixBuf,
"RPM_INSTALL_PREFIX=%s", prefixes[i]);
872 rootDir = ts->rootDir;
876 rootDir +=
sizeof(
"file://") - 1;
877 rootDir = strchr(rootDir,
'/');
881 !(rootDir[0] ==
'/' && rootDir[1] ==
'\0'))
890 argv[0], (
unsigned)getpid());
910 xx = execv(argv[0], (
char *
const *)argv);
933 if (!(psm->
sq.
reaped >= 0 && !strcmp(argv[0],
"/usr/sbin/glibc_post_upgrade") && WEXITSTATUS(psm->
sq.
status) == 110)) {
936 _(
"%s(%s-%s-%s.%s) scriptlet failed, waitpid(%d) rc %d: %s\n"),
943 _(
"%s(%s-%s-%s.%s) scriptlet failed, signal %d\n"),
944 sln, n, v, r, a, WTERMSIG(psm->
sq.
status));
947 _(
"%s(%s-%s-%s.%s) scriptlet failed, exit status %d\n"),
948 sln, n, v, r, a, WEXITSTATUS(psm->
sq.
status));
954 if (freePrefixes) prefixes = hfd(prefixes, ipt);
981 void ** progArgv = NULL;
983 const char * argv0 = NULL;
990 assert(fi->h != NULL);
991 xx = hge(fi->h, psm->
scriptTag, &stt, &script, NULL);
992 xx = hge(fi->h, psm->
progTag, &ptt, &progArgv, &progArgc);
993 if (progArgv == NULL && script == NULL)
998 argv =
alloca(
sizeof(*argv));
999 *argv = (
const char *) progArgv;
1001 argv = (
const char **) progArgv;
1005 if (argv && argv[0] && argv[0][0] ==
'%')
1006 argv[0] = argv0 =
rpmExpand(argv[0], NULL);
1013 argv0 =
_free(argv0);
1014 progArgv = hfd(progArgv, ptt);
1015 script = hfd(script, stt);
1031 int arg2,
unsigned char * triggersAlreadyRun)
1039 HGE_t hge = fi->hge;
1041 rpmds trigger = NULL;
1042 const char ** triggerScripts;
1043 const char ** triggerProgs;
1045 const char * sourceName;
1046 const char * triggerName;
1051 xx =
headerNVR(sourceH, &sourceName, NULL, NULL);
1052 xx =
headerNVR(triggeredH, &triggerName, NULL, NULL);
1055 if (trigger == NULL)
1065 if ((Name =
rpmdsN(trigger)) == NULL)
1068 if (strcmp(Name, sourceName))
1070 if (!(Flags & psm->
sense))
1080 &triggerIndices, NULL) &&
1082 &triggerScripts, NULL) &&
1084 &triggerProgs, NULL))
1097 index = triggerIndices[i];
1098 if (triggersAlreadyRun == NULL ||
1099 triggersAlreadyRun[index] == 0)
1101 rc =
runScript(psm, triggeredH,
"%trigger", 1,
1102 triggerProgs + index, triggerScripts[index],
1104 if (triggersAlreadyRun != NULL)
1105 triggersAlreadyRun[index] = 1;
1110 triggerIndices = hfd(triggerIndices, tit);
1111 triggerScripts = hfd(triggerScripts, tst);
1112 triggerProgs = hfd(triggerProgs, tpt);
1139 int numPackage = -1;
1141 const char * N = NULL;
1152 if (fi != NULL && fi->h != NULL)
1181 HGE_t hge = fi->hge;
1183 const char ** triggerNames;
1187 int numTriggerIndices;
1188 unsigned char * triggersRun;
1192 if (fi->h == NULL)
return rc;
1195 &triggerNames, &numTriggers) &&
1197 &triggerIndices, &numTriggerIndices))
1201 nb =
sizeof(*triggersRun) * numTriggerIndices;
1202 triggersRun = memset(
alloca(nb), 0, nb);
1207 for (i = 0; i < numTriggers; i++) {
1210 if (triggersRun[triggerIndices[i]] != 0)
continue;
1223 triggerIndices = hfd(triggerIndices, tit);
1224 triggerNames = hfd(triggerNames, tnt);
1264 default:
return "???";
1271 if (psm == NULL)
return NULL;
1274 fprintf(stderr,
"--> psm %p -- %d %s at %s:%u\n", psm, psm->
nrefs, msg, fn, ln);
1282 if (psm == NULL)
return NULL;
1287 fprintf(stderr,
"--> psm %p ++ %d %s at %s:%u\n", psm, psm->
nrefs, msg, fn, ln);
1295 const char * msg =
"rpmpsmFree";
1319 memset(psm, 0,
sizeof(*psm));
1330 const char * msg =
"rpmpsmNew";
1335 if (te) psm->
te = rpmteLink(te, msg);
1338 if (te) psm->
te =
te;
1502 const char * origin;
1505 assert(fi->h != NULL);
1546 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
1550 if (fi->fstates != NULL && fc > 0) {
1582 for (i = 0, entry = h->
index; i < h->indexUsed; i++, entry++) {
1584 memcpy(entry->
data,
"gzip", 4);
1600 HGE_t hge = fi->hge;
1601 HAE_t hae = fi->hae;
1628 assert(psm->
te != NULL);
1632 if (psm->
te->downgrade)
1645 assert(psm->
mi == NULL);
1647 if (hdrid != NULL) {
1676 if (fi->fstates == NULL && fc > 0) {
1677 fi->fstates =
xmalloc(
sizeof(*fi->fstates) * fc);
1691 fi->striplen = (xx ? strlen(p) + 1 : 1);
1701 if (fi->fuser == NULL)
1704 if (fi->fgroup == NULL)
1726 bfmt =
rpmGetPath(tiddn,
"/",
"%{_repackage_name_fmt}", NULL);
1731 "%{?_repackage_dir}",
1733 pkgbn =
_free(pkgbn);
1737 pkgdn =
_free(pkgdn);
1749 if (
rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
break;
1753 {
static int oneshot = 0;
1768 psm->
sense = RPMSENSE_TRIGGERPREIN;
1786 _(
"%s: %s scriptlet failed (%d), skipping %s\n"),
1797 psm->
sense = RPMSENSE_TRIGGERUN;
1814 int noArchiveSize = 0;
1815 const char * origin;
1851 if (ptr) xx = hae(psm->
oh, tag, type, ptr, count);
1870 memset(&lead, 0,
sizeof(lead));
1907 if (psm->
oh != NULL)
1924 assert(psm->
te != NULL);
1934 if (
rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
break;
1951 if (
rpmteFd(fi->te) == NULL) {
1959 if (psm->
cfd == NULL) {
1984 psm->
amount = (fi->archiveSize ? fi->archiveSize : 100);
1990 _(
"unpacking of archive failed%s%s: %s\n"),
2034 if (psm->
fd == NULL) {
2042 if (psm->
cfd == NULL) {
2064 psm->
amount = (fi->archiveSize ? fi->archiveSize : 100);
2068 fi->action = action;
2069 fi->actions = actions;
2073 if (
rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
break;
2094 psm->
sense = RPMSENSE_TRIGGERIN;
2111 if (!(
rpmtsFlags(ts) & RPMTRANS_FLAG_APPLYONLY))
2119 psm->
sense = RPMSENSE_TRIGGERPOSTUN;
2152 if (psm->
fd != NULL) {
2162 if (!rc && ts && ts->notify == NULL) {
2171 _(
"%s failed on file %s: %s\n"),
2188 if (psm->
te != NULL)
2189 if (psm->
te->h != NULL)
2201 fi->fgroup = hfd(fi->fgroup, -1);
2202 fi->fuser = hfd(fi->fuser, -1);
2203 fi->apath =
_free(fi->apath);
2204 fi->fstates =
_free(fi->fstates);
2245 if (rootDir != NULL && !(rootDir[0] ==
'/' && rootDir[1] ==
'\0')
2248 static int _pw_loaded = 0;
2249 static int _gr_loaded = 0;
2252 (void)getpwnam(
"root");
2257 (void)getgrnam(
"root");
2264 if (rootDir != NULL && strcmp(rootDir,
"/") && *rootDir ==
'/')
2277 if (rootDir != NULL && strcmp(rootDir,
"/") && *rootDir ==
'/')
2282 if (currDir != NULL)
2283 xx =
Chdir(currDir);
2291 if (
rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
break;
2296 if (
rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
break;
2301 {
const char * payload_compressor = NULL;
2302 const char * payload_format = NULL;
2307 &payload_compressor, NULL))
2308 payload_compressor =
"gzip";
2311 if (psm->
goal ==
PSM_PKGSAVE && !strcmp(payload_compressor,
"lzma") && access(
"/usr/bin/lzma",
X_OK)) {
2313 payload_compressor =
"gzip";
2317 if (!strcmp(payload_compressor,
"lzma")) {
2322 if (!strcmp(payload_compressor,
"gzip"))
2324 if (!strcmp(payload_compressor,
"bzip2"))
2330 &payload_format, NULL)
2331 || !(!strcmp(payload_format,
"tar") || !strcmp(payload_format,
"ustar")))
2332 payload_format =
"cpio";
2339 assert(psm->
mi == NULL);
2341 &fi->record,
sizeof(fi->record));
2347 if (fi->h != NULL) {
2355 if (fi->h == NULL)
break;
2371 assert(psm->
te != NULL);
2374 psm->
te->installed = 1;
2382 if (
rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
break;
2392 psm->
te->u.removed.dboffset = 0;