dcavalca / rpms / rpm

Forked from rpms/rpm a year ago
Clone

Blame rpm-4.14.3-fix-spurious-transfiletriggerpostun-execution.patch

James Antill ee2eaf
From f17aa638649fb8de730fecdbc906dc869b626ba5 Mon Sep 17 00:00:00 2001
James Antill ee2eaf
From: Panu Matilainen <pmatilai@redhat.com>
James Antill ee2eaf
Date: Tue, 16 Nov 2021 11:49:18 +0200
James Antill ee2eaf
Subject: [PATCH 1/2] Fix spurious %transfiletriggerpostun execution
James Antill ee2eaf
 (RhBug:2023311)
James Antill ee2eaf
James Antill ee2eaf
If a package has multiple %transfiletriggerpostun triggers, any one
James Antill ee2eaf
of them matching would cause all of them to run, due to disconnect
James Antill ee2eaf
in the intel gathering stage: we'd gather all the headers with matching
James Antill ee2eaf
files into a lump, and then add any postun triggers found in them,
James Antill ee2eaf
but this loses the triggering file information and causes all postuns
James Antill ee2eaf
to run.
James Antill ee2eaf
James Antill ee2eaf
The triggers need to be added while looping over the file matches,
James Antill ee2eaf
like runFileTriggers() does. Doing so actually simplifies the code.
James Antill ee2eaf
These should really be unified to use the same code, but leaving
James Antill ee2eaf
that exercise to another rainy day.
James Antill ee2eaf
---
James Antill ee2eaf
 lib/rpmtriggers.c | 64 +++++++++++++++++++++++------------------------
James Antill ee2eaf
 1 file changed, 31 insertions(+), 33 deletions(-)
James Antill ee2eaf
James Antill ee2eaf
diff --git a/lib/rpmtriggers.c b/lib/rpmtriggers.c
James Antill ee2eaf
index 0827af0c2..dc457f7cc 100644
James Antill ee2eaf
--- a/lib/rpmtriggers.c
James Antill ee2eaf
+++ b/lib/rpmtriggers.c
James Antill ee2eaf
@@ -97,19 +97,37 @@ static void rpmtriggersSortAndUniq(rpmtriggers trigs)
James Antill ee2eaf
     }
James Antill ee2eaf
 }
James Antill ee2eaf
 
James Antill ee2eaf
+static void addTriggers(rpmts ts, Header trigH, rpmsenseFlags filter)
James Antill ee2eaf
+{
James Antill ee2eaf
+    int tix = 0;
James Antill ee2eaf
+    rpmds ds;
James Antill ee2eaf
+    rpmds triggers = rpmdsNew(trigH, RPMTAG_TRANSFILETRIGGERNAME, 0);
James Antill ee2eaf
+
James Antill ee2eaf
+    while ((ds = rpmdsFilterTi(triggers, tix))) {
James Antill ee2eaf
+	if ((rpmdsNext(ds) >= 0) && (rpmdsFlags(ds) & filter)) {
James Antill ee2eaf
+	    struct rpmtd_s priorities;
James Antill ee2eaf
+
James Antill ee2eaf
+	    if (headerGet(trigH, RPMTAG_TRANSFILETRIGGERPRIORITIES,
James Antill ee2eaf
+			&priorities, HEADERGET_MINMEM)) {
James Antill ee2eaf
+		rpmtdSetIndex(&priorities, tix);
James Antill ee2eaf
+		rpmtriggersAdd(ts->trigs2run, headerGetInstance(trigH),
James Antill ee2eaf
+				tix, *rpmtdGetUint32(&priorities));
James Antill ee2eaf
+	    }
James Antill ee2eaf
+	}
James Antill ee2eaf
+	rpmdsFree(ds);
James Antill ee2eaf
+	tix++;
James Antill ee2eaf
+    }
James Antill ee2eaf
+    rpmdsFree(triggers);
James Antill ee2eaf
+}
James Antill ee2eaf
+
James Antill ee2eaf
 void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te)
James Antill ee2eaf
 {
James Antill ee2eaf
-    rpmdbMatchIterator mi;
James Antill ee2eaf
     rpmdbIndexIterator ii;
James Antill ee2eaf
-    Header trigH;
James Antill ee2eaf
     const void *key;
James Antill ee2eaf
     size_t keylen;
James Antill ee2eaf
     rpmfiles files;
James Antill ee2eaf
-    rpmds rpmdsTriggers;
James Antill ee2eaf
-    rpmds rpmdsTrigger;
James Antill ee2eaf
 
James Antill ee2eaf
     ii = rpmdbIndexIteratorInit(rpmtsGetRdb(ts), RPMDBI_TRANSFILETRIGGERNAME);
James Antill ee2eaf
-    mi = rpmdbNewIterator(rpmtsGetRdb(ts), RPMDBI_PACKAGES);
James Antill ee2eaf
     files = rpmteFiles(te);
James Antill ee2eaf
 
James Antill ee2eaf
     /* Iterate over file triggers in rpmdb */
James Antill ee2eaf
@@ -121,39 +139,19 @@ void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te)
James Antill ee2eaf
 	rpmfi fi = rpmfilesFindPrefix(files, pfx);
James Antill ee2eaf
 	while (rpmfiNext(fi) >= 0) {
James Antill ee2eaf
 	    if (RPMFILE_IS_INSTALLED(rpmfiFState(fi))) {
James Antill ee2eaf
-		/* If yes then store it */
James Antill ee2eaf
-		rpmdbAppendIterator(mi, rpmdbIndexIteratorPkgOffsets(ii),
James Antill ee2eaf
-				rpmdbIndexIteratorNumPkgs(ii));
James Antill ee2eaf
-		break;
James Antill ee2eaf
+		unsigned int npkg = rpmdbIndexIteratorNumPkgs(ii);
James Antill ee2eaf
+		const unsigned int *offs = rpmdbIndexIteratorPkgOffsets(ii);
James Antill ee2eaf
+		/* Save any matching postun triggers */
James Antill ee2eaf
+		for (int i = 0; i < npkg; i++) {
James Antill ee2eaf
+		    Header h = rpmdbGetHeaderAt(rpmtsGetRdb(ts), offs[i]);
James Antill ee2eaf
+		    addTriggers(ts, h, RPMSENSE_TRIGGERPOSTUN);
James Antill ee2eaf
+		    headerFree(h);
James Antill ee2eaf
+		}
James Antill ee2eaf
 	    }
James Antill ee2eaf
 	}
James Antill ee2eaf
 	rpmfiFree(fi);
James Antill ee2eaf
     }
James Antill ee2eaf
     rpmdbIndexIteratorFree(ii);
James Antill ee2eaf
-
James Antill ee2eaf
-    if (rpmdbGetIteratorCount(mi)) {
James Antill ee2eaf
-	/* Filter triggers and save only trans postun triggers into ts */
James Antill ee2eaf
-	while ((trigH = rpmdbNextIterator(mi)) != NULL) {
James Antill ee2eaf
-	    int tix = 0;
James Antill ee2eaf
-	    rpmdsTriggers = rpmdsNew(trigH, RPMTAG_TRANSFILETRIGGERNAME, 0);
James Antill ee2eaf
-	    while ((rpmdsTrigger = rpmdsFilterTi(rpmdsTriggers, tix))) {
James Antill ee2eaf
-		if ((rpmdsNext(rpmdsTrigger) >= 0) &&
James Antill ee2eaf
-		    (rpmdsFlags(rpmdsTrigger) & RPMSENSE_TRIGGERPOSTUN)) {
James Antill ee2eaf
-		    struct rpmtd_s priorities;
James Antill ee2eaf
-
James Antill ee2eaf
-		    headerGet(trigH, RPMTAG_TRANSFILETRIGGERPRIORITIES,
James Antill ee2eaf
-				&priorities, HEADERGET_MINMEM);
James Antill ee2eaf
-		    rpmtdSetIndex(&priorities, tix);
James Antill ee2eaf
-		    rpmtriggersAdd(ts->trigs2run, rpmdbGetIteratorOffset(mi),
James Antill ee2eaf
-				    tix, *rpmtdGetUint32(&priorities));
James Antill ee2eaf
-		}
James Antill ee2eaf
-		rpmdsFree(rpmdsTrigger);
James Antill ee2eaf
-		tix++;
James Antill ee2eaf
-	    }
James Antill ee2eaf
-	    rpmdsFree(rpmdsTriggers);
James Antill ee2eaf
-	}
James Antill ee2eaf
-    }
James Antill ee2eaf
-    rpmdbFreeIterator(mi);
James Antill ee2eaf
     rpmfilesFree(files);
James Antill ee2eaf
 }
James Antill ee2eaf
 
James Antill ee2eaf
-- 
James Antill ee2eaf
2.35.1
James Antill ee2eaf
James Antill ee2eaf
From e617e7c550d3523998707c55f96b37ede2c48c78 Mon Sep 17 00:00:00 2001
James Antill ee2eaf
From: Panu Matilainen <pmatilai@redhat.com>
James Antill ee2eaf
Date: Wed, 2 Feb 2022 13:46:23 +0200
James Antill ee2eaf
Subject: [PATCH 2/2] Really fix spurious %transfiletriggerpostun execution
James Antill ee2eaf
 (RhBug:2023311)
James Antill ee2eaf
James Antill ee2eaf
Commit b3d672a5523dfec033160e5cc866432a0e808649 got the base reasoning
James Antill ee2eaf
in the ballpark but the code all wrong, introducing a severe performance
James Antill ee2eaf
regression without actually fixing what it claimed to.
James Antill ee2eaf
James Antill ee2eaf
The missing incredient is actually comparing the current prefix with the
James Antill ee2eaf
triggers in matched package (trying to describe this makes my head
James Antill ee2eaf
spin): a package may have multiple triggers on multiple prefixes and
James Antill ee2eaf
we need to make sure we only execute triggers of this type, from this
James Antill ee2eaf
prefix.
James Antill ee2eaf
James Antill ee2eaf
This stuff really needs more and better testcases.
James Antill ee2eaf
James Antill ee2eaf
Fixes: b3d672a5523dfec033160e5cc866432a0e808649
James Antill ee2eaf
---
James Antill ee2eaf
 lib/rpmtriggers.c | 11 +++++++----
James Antill ee2eaf
 1 file changed, 7 insertions(+), 4 deletions(-)
James Antill ee2eaf
James Antill ee2eaf
diff --git a/lib/rpmtriggers.c b/lib/rpmtriggers.c
James Antill ee2eaf
index dc457f7cc..c652981be 100644
James Antill ee2eaf
--- a/lib/rpmtriggers.c
James Antill ee2eaf
+++ b/lib/rpmtriggers.c
James Antill ee2eaf
@@ -97,14 +97,16 @@ static void rpmtriggersSortAndUniq(rpmtriggers trigs)
James Antill ee2eaf
     }
James Antill ee2eaf
 }
James Antill ee2eaf
 
James Antill ee2eaf
-static void addTriggers(rpmts ts, Header trigH, rpmsenseFlags filter)
James Antill ee2eaf
+static void addTriggers(rpmts ts, Header trigH, rpmsenseFlags filter,
James Antill ee2eaf
+			const char *prefix)
James Antill ee2eaf
 {
James Antill ee2eaf
     int tix = 0;
James Antill ee2eaf
     rpmds ds;
James Antill ee2eaf
     rpmds triggers = rpmdsNew(trigH, RPMTAG_TRANSFILETRIGGERNAME, 0);
James Antill ee2eaf
 
James Antill ee2eaf
     while ((ds = rpmdsFilterTi(triggers, tix))) {
James Antill ee2eaf
-	if ((rpmdsNext(ds) >= 0) && (rpmdsFlags(ds) & filter)) {
James Antill ee2eaf
+	if ((rpmdsNext(ds) >= 0) && (rpmdsFlags(ds) & filter) &&
James Antill ee2eaf
+		strcmp(prefix, rpmdsN(ds)) == 0) {
James Antill ee2eaf
 	    struct rpmtd_s priorities;
James Antill ee2eaf
 
James Antill ee2eaf
 	    if (headerGet(trigH, RPMTAG_TRANSFILETRIGGERPRIORITIES,
James Antill ee2eaf
@@ -141,12 +143,13 @@ void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te)
James Antill ee2eaf
 	    if (RPMFILE_IS_INSTALLED(rpmfiFState(fi))) {
James Antill ee2eaf
 		unsigned int npkg = rpmdbIndexIteratorNumPkgs(ii);
James Antill ee2eaf
 		const unsigned int *offs = rpmdbIndexIteratorPkgOffsets(ii);
James Antill ee2eaf
-		/* Save any matching postun triggers */
James Antill ee2eaf
+		/* Save any postun triggers matching this prefix */
James Antill ee2eaf
 		for (int i = 0; i < npkg; i++) {
James Antill ee2eaf
 		    Header h = rpmdbGetHeaderAt(rpmtsGetRdb(ts), offs[i]);
James Antill ee2eaf
-		    addTriggers(ts, h, RPMSENSE_TRIGGERPOSTUN);
James Antill ee2eaf
+		    addTriggers(ts, h, RPMSENSE_TRIGGERPOSTUN, pfx);
James Antill ee2eaf
 		    headerFree(h);
James Antill ee2eaf
 		}
James Antill ee2eaf
+		break;
James Antill ee2eaf
 	    }
James Antill ee2eaf
 	}
James Antill ee2eaf
 	rpmfiFree(fi);
James Antill ee2eaf
-- 
James Antill ee2eaf
2.35.1
James Antill ee2eaf