wuyuoss / rpms / rpm

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