Revision: 460
          http://vde.svn.sourceforge.net/vde/?rev=460&view=rev
Author:   rd235
Date:     2011-01-14 21:13:49 +0000 (Fri, 14 Jan 2011)

Log Message:
-----------
plugins: std search path mgmt. path, ~/vde-2/plugins, {stdlib}/vde2/plugins

Modified Paths:
--------------
    trunk/vde-2/configure.ac
    trunk/vde-2/src/vde_switch/Makefile.am
    trunk/vde-2/src/vde_switch/consmgmt.c

Modified: trunk/vde-2/configure.ac
===================================================================
--- trunk/vde-2/configure.ac    2011-01-14 17:08:05 UTC (rev 459)
+++ trunk/vde-2/configure.ac    2011-01-14 21:13:49 UTC (rev 460)
@@ -18,6 +18,8 @@
 AC_PROG_LIBTOOL
 AM_PROG_CC_C_O
 
+AC_DEFINE_UNQUOTED(MODULES_EXT, "$shrext_cmds", [Extension of shared objects])
+
 # Checks for libraries.
 AC_CHECK_LIB([dl], [dlopen])
 AC_CHECK_LIB([crypto], [EVP_EncryptInit],

Modified: trunk/vde-2/src/vde_switch/Makefile.am
===================================================================
--- trunk/vde-2/src/vde_switch/Makefile.am      2011-01-14 17:08:05 UTC (rev 
459)
+++ trunk/vde-2/src/vde_switch/Makefile.am      2011-01-14 21:13:49 UTC (rev 
460)
@@ -42,6 +42,6 @@
 if ENABLE_EXPERIMENTAL
   SUBDIRS = plugins
   AM_CFLAGS += $(EXP_CFLAGS)
-  AM_CPPFLAGS += -DDEBUGOPT -DPORTCOUNTERS -DVDEPLUGIN
+  AM_CPPFLAGS += -DDEBUGOPT -DPORTCOUNTERS -DVDEPLUGIN 
-DPLUGINS_DIR=\"$(pkglibdir)/plugins\"
 endif
 

Modified: trunk/vde-2/src/vde_switch/consmgmt.c
===================================================================
--- trunk/vde-2/src/vde_switch/consmgmt.c       2011-01-14 17:08:05 UTC (rev 
459)
+++ trunk/vde-2/src/vde_switch/consmgmt.c       2011-01-14 21:13:49 UTC (rev 
460)
@@ -804,11 +804,76 @@
        return rv;
 }
 
+/* This will be prefixed with getent("$HOME") */
+#define USER_PLUGINS_DIR "/.vde2/plugins"
+
+#ifndef MAX
+# define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+/*
+ * Try to dlopen a plugin trying different names and locations:
+ * (code from view-os by Gardenghi)
+ * 
+ * 1) dlopen(modname)
+ * 2) dlopen(modname.so)
+ * 3) dlopen(user_umview_plugin_directory/modname)
+ * 4) dlopen(user_umview_plugin_directory/modname.so)
+ * 5) dlopen(global_umview_plugin_directory/modname)
+ * 6) dlopen(global_umview_plugin_directory/modname.so)
+ *
+ */
+
+#define TRY_DLOPEN(fmt...) \
+{ \
+       snprintf(testpath, tplen, fmt); \
+       if ((handle = dlopen(testpath, flag))) \
+       { \
+               free(testpath); \
+               return handle; \
+       } \
+}
+
+void *plugin_dlopen(const char *modname, int flag)
+{
+       void *handle;
+       char *testpath;
+       int tplen;
+       char *homedir = getenv("HOME");
+
+       if (!modname)
+               return NULL;
+
+       if ((handle = dlopen(modname, flag)))
+               return handle;
+
+       /* If there is no home directory, use CWD */
+       if (!homedir)
+               homedir = ".";
+
+       tplen = strlen(modname) +
+               strlen(MODULES_EXT) + 2 + // + 1 is for a '/' and + 1 for \0
+               MAX(strlen(PLUGINS_DIR),
+                               strlen(homedir) + strlen(USER_PLUGINS_DIR));
+
+         testpath = malloc(tplen);
+
+               TRY_DLOPEN("%s%s", modname, MODULES_EXT);
+               TRY_DLOPEN("%s%s/%s", homedir, USER_PLUGINS_DIR, modname);
+               TRY_DLOPEN("%s%s/%s%s", homedir, USER_PLUGINS_DIR, modname, 
MODULES_EXT);
+               TRY_DLOPEN("%s%s", PLUGINS_DIR, modname);
+               TRY_DLOPEN("%s/%s%s", PLUGINS_DIR, modname, MODULES_EXT);
+
+               free(testpath);
+               return NULL;
+}
+
+
+
 static int pluginadd(char *arg) {
        void *handle;
        struct plugin *p;
        int rv=ENOENT;
-       if ((handle=dlopen(arg,RTLD_LAZY)) != NULL) {
+       if ((handle=plugin_dlopen(arg,RTLD_LAZY)) != NULL) {
                if ((p=(struct plugin *) dlsym(handle,"vde_plugin_data")) != 
NULL) {
                        if (p->handle != NULL) { /* this dyn library is already 
loaded*/
                                dlclose(handle);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
vde-users mailing list
vde-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vde-users

Reply via email to