[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[RFC] Put frontend plugins symbol in the "cdebconf_" namespaces



Hi!

As suggested by Colin [1]: this patch will put
frontend plugins symbol in the "cdebconf_" namespaces.

[1] http://lists.debian.org/debian-boot/2007/08/msg00006.html

The old symbols are still looked up as a fallback to ensure compatibility.
Fix a memory leak in plugin_new() along the way.
---
 packages/cdebconf/debian/changelog |    3 +++
 packages/cdebconf/doc/plugins.txt  |    6 +++---
 packages/cdebconf/src/plugin.c     |   15 ++++++++++++---
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/packages/cdebconf/debian/changelog b/packages/cdebconf/debian/changelog
index 2344d31..2231249 100644
--- a/packages/cdebconf/debian/changelog
+++ b/packages/cdebconf/debian/changelog
@@ -21,6 +21,9 @@ cdebconf (0.120) UNRELEASED; urgency=low
   * Load frontend with RTLD_NOW | RTLD_GLOBAL to allow plugins to access
     frontend API without requiring calls to dlsym().  Kudos to Steve Langasek
     for the help to figure this out!
+  * Put frontend plugins symbol in the "cdebconf_" namespaces.  The old
+    symbols are still looked up as a fallback to ensure compatibility.
+  * Fix a memory leak in plugin_new() along the way. 
 
  -- Joey Hess <joeyh@debian.org>  Fri, 17 Aug 2007 13:54:30 -0400
 
diff --git a/packages/cdebconf/doc/plugins.txt b/packages/cdebconf/doc/plugins.txt
index d491cee..1b4ea63 100644
--- a/packages/cdebconf/doc/plugins.txt
+++ b/packages/cdebconf/doc/plugins.txt
@@ -26,7 +26,7 @@ would be stored in:
 
 The library must provide a function with the following name:
 
-  <frontend>_handler_<type>
+  cdebconf_<frontend>_handler_<type>
 
 Any hyphens in <type> here are substituted with underscores, so:
 
@@ -35,11 +35,11 @@ Any hyphens in <type> here are substituted with underscores, so:
 The required prototype for this function depends on the frontend. For newt
 and text, it is (again with hyphens in <type> substituted with underscores):
 
-  int <frontend>_handler_<type>(struct frontend *obj, struct question *q)
+  int cdebconf_<frontend>_handler_<type>(struct frontend *obj, struct question *q)
 
 For gtk, it is:
 
-  int <frontend>_handler_<type>(struct frontend *obj, struct question *q, GtkWidget *questionbox);
+  int cdebconf_<frontend>_handler_<type>(struct frontend *obj, struct question *q, GtkWidget *questionbox);
 
 The handler should return DC_OK (defined in common.h) if all went well,
 DC_GOBACK if the user wants to back up to the previous question, or DC_NOTOK
diff --git a/packages/cdebconf/src/plugin.c b/packages/cdebconf/src/plugin.c
index f09b0c8..ad28b47 100644
--- a/packages/cdebconf/src/plugin.c
+++ b/packages/cdebconf/src/plugin.c
@@ -59,11 +59,20 @@ struct plugin *plugin_new(const char *frontend, const char *filename)
         return NULL;
     }
 
-    symbollen = strlen(frontend) + 9 + strlen(plugin->name) + 1;
+    symbollen = strlen(frontend) + 18 + strlen(plugin->name) + 1;
     symbol = malloc(symbollen);
-    snprintf(symbol, symbollen, "%s_handler_%s", frontend, typesymbol);
-
+    snprintf(symbol, symbollen, "cdebconf_%s_handler_%s", frontend,
+             typesymbol);
     plugin->handler = dlsym(plugin->module, symbol);
+    free(symbol);
+    if (plugin->handler == NULL) {
+        /* Let's try with the old style symbol name. */
+        symbollen = strlen(frontend) + 9 + strlen(plugin->name) + 1;
+        symbol = malloc(symbollen);
+        snprintf(symbol, symbollen, "%s_handler_%s", frontend, typesymbol);
+        plugin->handler = dlsym(plugin->module, symbol);
+        free(symbol);
+    }
     if (plugin->handler == NULL) {
         INFO(INFO_WARN, "Malformed plugin module %s", filename);
         plugin_delete(plugin);

-- 
Jérémy Bobbio                        .''`. 
lunar@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   

Attachment: signature.asc
Description: Digital signature


Reply to: