diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 8 | ||||
-rw-r--r-- | src/plugin.cpp | 79 | ||||
-rw-r--r-- | src/screen.cpp | 3 |
3 files changed, 54 insertions, 36 deletions
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); |