michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
4c9460
From b62a75b137bde84ec8bac92c0238502b422c56ce Mon Sep 17 00:00:00 2001
4c9460
From: Panu Matilainen <pmatilai@redhat.com>
4c9460
Date: Tue, 24 Jun 2014 14:37:38 +0300
4c9460
Subject: [PATCH] Initialize plugins based on DSO discovery
4c9460
4c9460
- %__transaction_plugins style configuration is problematic for plugins
4c9460
  because we want plugins to be, well, pluggable. As in drop-in to
4c9460
  enable, which is not achievable with a single macro entry. Look up
4c9460
  all DSO's from the plugin dir and enable if a matching
4c9460
  %__transaction_foo macro is defined.
4c9460
- This isn't optimal but it'll buy us the drop-in capability, which
4c9460
  is what matters most right now. We'll want to have forcability as
4c9460
  well later on (ie it should be possible to require given plugins
4c9460
  to be present)
4c9460
4c9460
Conflicts:
4c9460
	lib/transaction.c
4c9460
---
4c9460
 lib/rpmplugins.c  |  3 ++-
4c9460
 lib/transaction.c | 34 +++++++++++++++++-----------------
4c9460
 2 files changed, 19 insertions(+), 18 deletions(-)
4c9460
4c9460
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
4c9460
index 7285f54..4e600db 100644
4c9460
--- a/lib/rpmplugins.c
4c9460
+++ b/lib/rpmplugins.c
4c9460
@@ -84,8 +84,9 @@ rpmRC rpmpluginsAddPlugin(rpmPlugins plugins, const char *type, const char *name
4c9460
 
4c9460
     path = rpmExpand("%{?__", type, "_", name, "}", NULL);
4c9460
     if (!path || rstreq(path, "")) {
4c9460
-	rpmlog(RPMLOG_ERR, _("Failed to expand %%__%s_%s macro\n"),
4c9460
+	rpmlog(RPMLOG_DEBUG, _("Plugin %%__%s_%s not configured\n"),
4c9460
 	       type, name);
4c9460
+	rc = RPMRC_NOTFOUND;
4c9460
 	goto exit;
4c9460
     }
4c9460
 
4c9460
diff --git a/lib/transaction.c b/lib/transaction.c
4c9460
index 08a5643..386f107 100644
4c9460
--- a/lib/transaction.c
4c9460
+++ b/lib/transaction.c
4c9460
@@ -1440,29 +1440,29 @@ static int rpmtsProcess(rpmts ts)
4c9460
 static rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
4c9460
 {
4c9460
     rpmRC rc = RPMRC_OK;
4c9460
-    char *plugins = NULL, *plugin = NULL;
4c9460
-    const char *delims = ",";
4c9460
+    ARGV_t files = NULL;
4c9460
+    int nfiles = 0;
4c9460
+    char *dsoPath = NULL;
4c9460
 
4c9460
-    plugins = rpmExpand("%{?__transaction_plugins}", NULL);
4c9460
-    if (!plugins || rstreq(plugins, "")) {
4c9460
-	goto exit;
4c9460
-    }
4c9460
+    /*
4c9460
+     * Assume allocated equals initialized. There are some oddball cases
4c9460
+     * (verification of non-installed package) where this is not true
4c9460
+     * currently but that's not a new issue.
4c9460
+     */
4c9460
 
4c9460
-    plugin = strtok(plugins, delims);
4c9460
-    while(plugin != NULL) {
4c9460
-	rpmlog(RPMLOG_DEBUG, "plugin is %s\n", plugin);
4c9460
-	if (!rpmpluginsPluginAdded(ts->plugins, (const char*)plugin)) {
4c9460
-	    if (rpmpluginsAddPlugin(ts->plugins, "transaction",
4c9460
-				    (const char*)plugin) == RPMRC_FAIL) {
4c9460
-		/* any configured plugin failing to load is a failure */
4c9460
+    dsoPath = rpmExpand("%{__plugindir}/*.so", NULL);
4c9460
+    if (rpmGlob(dsoPath, &nfiles, &files) == 0) {
4c9460
+	rpmPlugins tsplugins = rpmtsPlugins(ts);
4c9460
+	for (int i = 0; i < nfiles; i++) {
4c9460
+	    char *bn = basename(files[i]);
4c9460
+	    bn[strlen(bn)-strlen(".so")] = '\0';
4c9460
+	    if (rpmpluginsAddPlugin(tsplugins, "transaction", bn) == RPMRC_FAIL)
4c9460
 		rc = RPMRC_FAIL;
4c9460
-	    }
4c9460
 	}
4c9460
-	plugin = strtok(NULL, delims);
4c9460
+	files = argvFree(files);
4c9460
     }
4c9460
+    free(dsoPath);
4c9460
 
4c9460
-exit:
4c9460
-    free(plugins);
4c9460
     return rc;
4c9460
 }
4c9460
 
4c9460
-- 
4c9460
2.1.0
4c9460