summaryrefslogtreecommitdiff
path: root/src/plugin.cpp
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2009-02-25 22:42:20 +0100
committerDanny Baumann <dannybaumann@web.de>2009-02-25 22:42:20 +0100
commitff4a12d214bfa591d562228609d8780b69bba304 (patch)
tree828b33f1428b3bd482bf86ae31db4fadd7e5f80c /src/plugin.cpp
parentcdf374c02dc8d16f13be1b0260d738172592ab1a (diff)
downloadunity-window-decorator-ff4a12d214bfa591d562228609d8780b69bba304.tar.gz
unity-window-decorator-ff4a12d214bfa591d562228609d8780b69bba304.tar.bz2
Get plugin loading improvements from 0.8 branch and add --debug command
line parameter that enables logging of CompLogLevelDebug messages on stdout.
Diffstat (limited to 'src/plugin.cpp')
-rw-r--r--src/plugin.cpp79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 60071a2..4b1c3df 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -28,6 +28,9 @@
#include <string.h>
#include <dlfcn.h>
#include <dirent.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <list>
#include <boost/foreach.hpp>
@@ -123,19 +126,34 @@ dlloaderLoadPlugin (CompPlugin *p,
const char *path,
const char *name)
{
- char *file;
- void *dlhand;
+ CompString file;
+ void *dlhand;
+ bool loaded = false;
+ struct stat fileInfo;
- file = (char *) malloc ((path ? strlen (path) : 0) + strlen (name) + 8);
- if (!file)
- return false;
+ if (cloaderLoadPlugin (p, path, name))
+ return true;
if (path)
- sprintf (file, "%s/lib%s.so", path, name);
- else
- sprintf (file, "lib%s.so", name);
+ {
+ file = path;
+ file += "/";
+ }
+
+ file += "lib";
+ file += name;
+ file += ".so";
- dlhand = dlopen (file, RTLD_LAZY);
+ if (stat (file.c_str (), &fileInfo) != 0)
+ {
+ /* file likely not present */
+ compLogMessage ("core", CompLogLevelDebug,
+ "Could not stat() file %s : %s",
+ file.c_str (), strerror (errno));
+ return false;
+ }
+
+ dlhand = dlopen (file.c_str (), RTLD_LAZY);
if (dlhand)
{
PluginGetInfoProc getInfo;
@@ -144,15 +162,13 @@ dlloaderLoadPlugin (CompPlugin *p,
dlerror ();
- snprintf(sym, 1024, "getCompPluginVTable20081216_%s", name);
- getInfo = (PluginGetInfoProc)
- dlsym (dlhand, sym);
+ snprintf (sym, 1024, "getCompPluginVTable20081216_%s", name);
+ getInfo = (PluginGetInfoProc) dlsym (dlhand, sym);
error = dlerror ();
if (error)
{
compLogMessage ("core", CompLogLevelError, "dlsym: %s", error);
-
getInfo = 0;
}
@@ -162,41 +178,34 @@ dlloaderLoadPlugin (CompPlugin *p,
if (!p->vTable)
{
compLogMessage ("core", CompLogLevelError,
- "Couldn't get vtable from '%s' plugin", file);
-
- dlclose (dlhand);
- free (file);
-
- return false;
+ "Couldn't get vtable from '%s' plugin",
+ file.c_str ());
+ }
+ else
+ {
+ p->devPrivate.ptr = dlhand;
+ p->devType = "dlloader";
+ loaded = true;
}
- }
- else
- {
- dlclose (dlhand);
- free (file);
-
- return false;
}
}
else
{
- free (file);
-
- return cloaderLoadPlugin (p, path, name);
+ compLogMessage ("core", CompLogLevelError,
+ "Couldn't load plugin '%s' : %s",
+ file.c_str (), dlerror ());
}
- free (file);
+ if (!loaded && dlhand)
+ dlclose (dlhand);
- p->devPrivate.ptr = dlhand;
- p->devType = "dlloader";
-
- return true;
+ return loaded;
}
static void
dlloaderUnloadPlugin (CompPlugin *p)
{
- if (p->devType.compare ("dlloader") == 0)
+ if (p->devType == "dlloader")
{
delete p->vTable;
dlclose (p->devPrivate.ptr);