chantra / rpms / rpm

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