summaryrefslogtreecommitdiff
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
parentcdf374c02dc8d16f13be1b0260d738172592ab1a (diff)
downloadcompiz-with-glib-mainloop-ff4a12d214bfa591d562228609d8780b69bba304.tar.gz
compiz-with-glib-mainloop-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.
-rw-r--r--include/core/screen.h1
-rw-r--r--src/main.cpp8
-rw-r--r--src/plugin.cpp79
-rw-r--r--src/screen.cpp3
4 files changed, 55 insertions, 36 deletions
diff --git a/include/core/screen.h b/include/core/screen.h
index 2132d30..4a9c23f 100644
--- a/include/core/screen.h
+++ b/include/core/screen.h
@@ -45,6 +45,7 @@ extern char *backgroundImage;
extern bool replaceCurrentWm;
extern bool indirectRendering;
extern bool noDetection;
+extern bool debugOutput;
extern CompScreen *screen;
extern CompMetadata *coreMetadata;
diff --git a/src/main.cpp b/src/main.cpp
index b9ba1c5..7adf004 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -54,6 +54,7 @@ bool replaceCurrentWm = false;
bool indirectRendering = false;
bool noDetection = false;
bool useDesktopHints = true;
+bool debugOutput = false;
bool useCow = true;
@@ -73,7 +74,8 @@ usage (void)
"[--sm-client-id ID] "
"[--no-detection]\n "
"[--ignore-desktop-hints] "
- " [--use-root-window]\n "
+ "[--use-root-window]\n "
+ "[--debug] "
"[--version] "
"[--help] "
"[PLUGIN]...\n",
@@ -179,6 +181,10 @@ main (int argc, char **argv)
printf (PACKAGE_STRING "\n");
return 0;
}
+ else if (!strcmp (argv[i], "--debug"))
+ {
+ debugOutput = true;
+ }
else if (!strcmp (argv[i], "--display"))
{
if (i + 1 < argc)
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);
diff --git a/src/screen.cpp b/src/screen.cpp
index 602f3b4..33527b9 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -1422,6 +1422,9 @@ logMessage (const char *componentName,
CompLogLevel level,
const char *message)
{
+ if (!debugOutput && level >= CompLogLevelDebug)
+ return;
+
fprintf (stderr, "%s (%s) - %s: %s\n",
programName, componentName,
logLevelToString (level), message);