Index: include/libroar/roardl.h
===================================================================
--- include/libroar/roardl.h	(revision 5381)
+++ include/libroar/roardl.h	(revision 5427)
@@ -40,7 +40,9 @@
 
 #define ROAR_DL_FLAG_DEFAULTS          -1
+#define ROAR_DL_FLAG_PLUGIN            -2
 #define ROAR_DL_FLAG_NONE               0x0000
 #define ROAR_DL_FLAG_STATIC             0x0001 /* plugins are linked statically -lfoo */
 #define ROAR_DL_FLAG_LAZY               0x0002
+#define ROAR_DL_FLAG_PLUGINPATH         0x0004 /* Use plugin search path */
 
 #define ROAR_DL_HANDLE_DEFAULT          ((struct roar_dl_lhandle*)(void*)0)
Index: libroar/plugincontainer.c
===================================================================
--- libroar/plugincontainer.c	(revision 5425)
+++ libroar/plugincontainer.c	(revision 5427)
@@ -35,8 +35,4 @@
 
 #include "libroar.h"
-
-#ifdef ROAR_HAVE_H_DIRENT
-#include <dirent.h>
-#endif
 
 #define MAX_PLUGINS 64
@@ -144,113 +140,4 @@
 
 // plugin loading and unloading:
-#ifdef ROAR_HAVE_H_DIRENT
-// pvn = prefix, host vendor, host name
-static struct roar_dl_lhandle * _load_from_path_pvn(const char * name,
-                                                       struct roar_dl_librarypara * para,
-                                                       const char * prefix,
-                                                       const char * hostvendor,
-                                                       const char * hostname) {
- struct roar_dl_lhandle * ret = NULL;
- int i, j;
- char path[1024];
- const char * path_format[] = {"%s/%s/%s", "%s/%s/universal", "%s/universal/universal"};
- DIR * dir;
- struct dirent * dirent;
- char file[1024];
- const char * file_format[] = {"%s/%s/%s", "%s/%s/%s" ROAR_SHARED_SUFFIX, "%s/%s/lib%s" ROAR_SHARED_SUFFIX};
-//  cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para);
-//#vars: $PREFIX_PLUGINS, $hostvendor, $hostname, $name
-//#search order: $PREFIX_PLUGINS/{$hostvendor/{$hostname,universal},universal/universal}/*/{,lib}$name.so
-
- for (i = 0; i < 3; i++) {
-  snprintf(path, sizeof(path), path_format[i], prefix, hostvendor, hostname);
-  dir = opendir(path);
-  if ( dir == NULL )
-   continue;
-
-  while ((dirent = readdir(dir)) != NULL) {
-   if ( !strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..") )
-    continue;
-
-   for (j = 0; j < 3; j++) {
-    snprintf(file, sizeof(file), file_format[j], path, dirent->d_name, name);
-    ret = roar_dl_open(file, ROAR_DL_FLAG_DEFAULTS, 1, para);
-    if ( ret != NULL ) {
-     closedir(dir);
-     return ret;
-    }
-   }
-  }
-
-  closedir(dir);
- }
-
- return NULL;
-}
-
-static struct roar_dl_lhandle * _load_from_path(const char * name, struct roar_dl_librarypara * para) {
- struct roar_dl_lhandle * ret = NULL;
- char * host = NULL;
- char * hostvendor_buffer = NULL;
- char * hostvendor = NULL;
- char * hostname = NULL;
- char * c, * d;
-
- if ( para->appname != NULL && para->appname[0] != 0 ) {
-  host = roar_mm_strdup(para->appname);
-
-  // if we are out of memory we will likely not pass the rest, so just return in error.
-  if ( host == NULL )
-   return NULL;
-
-  hostname = host;
-  c = strstr(host, "<");
-  if ( c != NULL ) {
-   while (c[-1] == ' ') c--;
-   *c = 0;
-   c++;
-   while (*c == ' ' || *c == '<') c++;
-   if ( *c ) {
-    d = strstr(c, ">");
-    if ( d != NULL )
-     *d = 0;
-
-    d = strstr(c, "/");
-    if ( d != NULL ) {
-     *d = '-';
-     hostvendor = c;
-    } else {
-     hostvendor_buffer = roar_mm_malloc(roar_mm_strlen(c) + 1 /* tailing \0 */ + 6 /* "unreg-" */);
-
-     // see above
-     if ( hostvendor_buffer == NULL ) {
-      roar_mm_free(host);
-      return NULL;
-     }
-
-     strcpy(hostvendor_buffer, "unreg-");
-     strcat(hostvendor_buffer, c);
-     hostvendor = hostvendor_buffer;
-    }
-   }
-  }
- }
-
- if ( hostvendor == NULL )
-  hostvendor = "universal";
-
- if ( hostname == NULL )
-  hostname = "universal";
-
- ret = _load_from_path_pvn(name, para, ROAR_PREFIX_PLUGINS, hostvendor, hostname);
-
- if ( host != NULL )
-  roar_mm_free(host);
- if ( hostvendor_buffer != NULL )
-  roar_mm_free(hostvendor_buffer);
- return ret;
-}
-#endif
-
 int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para) {
  ssize_t idx = -1;
@@ -285,15 +172,5 @@
  }
 
- if ( strstr(name, "/") != NULL ) {
-  cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para);
- } else {
-#ifdef ROAR_HAVE_H_DIRENT
-  cont->handle[idx] = _load_from_path(name, para);
-#else
-  roar_err_set(ROAR_ERROR_NOSYS);
-  return -1;
-#endif
- }
-
+ cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_PLUGIN, 1, para);
  if ( cont->handle[idx] == NULL )
   return -1;
Index: libroar/roardl.c
===================================================================
--- libroar/roardl.c	(revision 5381)
+++ libroar/roardl.c	(revision 5427)
@@ -36,4 +36,8 @@
 #include "libroar.h"
 
+#ifdef ROAR_HAVE_H_DIRENT
+#include <dirent.h>
+#endif
+
 #if defined(ROAR_HAVE_LIBDL) && !defined(RTLD_NEXT)
 #define RTLD_NEXT ((void *) -1L)
@@ -191,4 +195,128 @@
 #endif
 
+#ifdef ROAR_HAVE_H_DIRENT
+// pvn = prefix, host vendor, host name
+static struct roar_dl_lhandle * _load_from_path_pvn(const char * name,
+                                                    int flags, int ra_init,
+                                                    struct roar_dl_librarypara * para,
+                                                    const char * prefix,
+                                                    const char * hostvendor,
+                                                    const char * hostname) {
+ struct roar_dl_lhandle * ret = NULL;
+ int i, j;
+ char path[1024];
+ const char * path_format[] = {"%s/%s/%s", "%s/%s/universal", "%s/universal/universal"};
+ DIR * dir;
+ struct dirent * dirent;
+ char file[1024];
+ const char * file_format[] = {"%s/%s/%s", "%s/%s/%s" ROAR_SHARED_SUFFIX, "%s/%s/lib%s" ROAR_SHARED_SUFFIX};
+//  cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para);
+//#vars: $PREFIX_PLUGINS, $hostvendor, $hostname, $name
+//#search order: $PREFIX_PLUGINS/{$hostvendor/{$hostname,universal},universal/universal}/*/{,lib}$name.so
+
+ for (i = 0; i < 3; i++) {
+  snprintf(path, sizeof(path), path_format[i], prefix, hostvendor, hostname);
+  dir = opendir(path);
+  if ( dir == NULL )
+   continue;
+
+  while ((dirent = readdir(dir)) != NULL) {
+   if ( !strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..") )
+    continue;
+
+   for (j = 0; j < 3; j++) {
+    snprintf(file, sizeof(file), file_format[j], path, dirent->d_name, name);
+    ret = roar_dl_open(file, flags, ra_init, para);
+    if ( ret != NULL ) {
+     closedir(dir);
+     return ret;
+    }
+   }
+  }
+
+  closedir(dir);
+ }
+
+ return NULL;
+}
+
+static struct roar_dl_lhandle * _load_from_path(const char * name, int flags, int ra_init,
+                                                struct roar_dl_librarypara * para) {
+ struct roar_dl_lhandle * ret = NULL;
+ char * host = NULL;
+ char * hostvendor_buffer = NULL;
+ char * hostvendor = NULL;
+ char * hostname = NULL;
+ char * c, * d;
+
+ if ( para != NULL && para->appname != NULL && para->appname[0] != 0 ) {
+  host = roar_mm_strdup(para->appname);
+
+  // if we are out of memory we will likely not pass the rest, so just return in error.
+  if ( host == NULL )
+   return NULL;
+
+  hostname = host;
+  c = strstr(host, "<");
+  if ( c != NULL ) {
+   while (c[-1] == ' ') c--;
+   *c = 0;
+   c++;
+   while (*c == ' ' || *c == '<') c++;
+   if ( *c ) {
+    d = strstr(c, ">");
+    if ( d != NULL )
+     *d = 0;
+
+    d = strstr(c, "/");
+    if ( d != NULL ) {
+     *d = '-';
+     hostvendor = c;
+    } else {
+     hostvendor_buffer = roar_mm_malloc(roar_mm_strlen(c) + 1 /* tailing \0 */ + 6 /* "unreg-" */);
+
+     // see above
+     if ( hostvendor_buffer == NULL ) {
+      roar_mm_free(host);
+      return NULL;
+     }
+
+     strcpy(hostvendor_buffer, "unreg-");
+     strcat(hostvendor_buffer, c);
+     hostvendor = hostvendor_buffer;
+    }
+   }
+  }
+ }
+
+ if ( hostvendor == NULL )
+  hostvendor = "universal";
+
+ if ( hostname == NULL )
+  hostname = "universal";
+
+ ret = _load_from_path_pvn(name, flags, ra_init, para, ROAR_PREFIX_PLUGINS, hostvendor, hostname);
+
+ if ( host != NULL )
+  roar_mm_free(host);
+ if ( hostvendor_buffer != NULL )
+  roar_mm_free(hostvendor_buffer);
+ return ret;
+}
+#endif
+
+static struct roar_dl_lhandle * _roar_dl_open_pluginpath(const char * filename, int flags,
+                                      int ra_init, struct roar_dl_librarypara * para) {
+ flags |= ROAR_DL_FLAG_PLUGINPATH;
+ flags -= ROAR_DL_FLAG_PLUGINPATH;
+
+#ifdef ROAR_HAVE_H_DIRENT
+ return _load_from_path(filename, flags, ra_init, para);
+#else
+ // fall back to system open function.
+ return roar_dl_open(filename, flags, ra_init, para);
+#endif
+}
+
 struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags,
                                       int ra_init, struct roar_dl_librarypara * para) {
@@ -203,6 +331,11 @@
  int err;
 
- if ( flags == ROAR_DL_FLAG_DEFAULTS )
-  flags = ROAR_DL_FLAG_NONE;
+ switch (flags) {
+  case ROAR_DL_FLAG_DEFAULTS: flags = ROAR_DL_FLAG_NONE;       break;
+  case ROAR_DL_FLAG_PLUGIN:   flags = ROAR_DL_FLAG_PLUGINPATH; break;
+ }
+
+ if ( flags & ROAR_DL_FLAG_PLUGINPATH )
+  return _roar_dl_open_pluginpath(filename, flags, ra_init, para);
 
 #if defined(ROAR_HAVE_LIBDL)
Index: roarclients/roarpluginrunner.c
===================================================================
--- roarclients/roarpluginrunner.c	(revision 5381)
+++ roarclients/roarpluginrunner.c	(revision 5427)
@@ -53,5 +53,5 @@
 
 static int do_run(const char * name) {
- struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, g_para);
+ struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_PLUGIN, 1, g_para);
 
  if ( lhandle == NULL )
@@ -110,5 +110,5 @@
 
 static int do_explain(const char * name) {
- struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_LAZY, 0, NULL);
+ struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_LAZY|ROAR_DL_FLAG_PLUGINPATH, 0, g_para);
  struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para);
  struct roar_dl_libraryinst * lib;
Index: roard/plugins.c
===================================================================
--- roard/plugins.c	(revision 5381)
+++ roard/plugins.c	(revision 5427)
@@ -161,5 +161,5 @@
  }
 
- next->lhandle = roar_dl_open(filename, ROAR_DL_FLAG_DEFAULTS, 0 /* we delay this until plugins_init() */, para);
+ next->lhandle = roar_dl_open(filename, ROAR_DL_FLAG_PLUGIN, 0 /* we delay this until plugins_init() */, para);
  roar_dl_para_unref(para);
 
