diff options
author | Danny Baumann <dannybaumann@web.de> | 2008-12-18 10:03:51 +0100 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2008-12-18 10:03:51 +0100 |
commit | 81c16e76542dd9ee5d504473c48ccf326474919f (patch) | |
tree | b5c99fab2bcf017fa74b2cf128e3f648d62899a1 /src | |
parent | 54842d1d15dbe2a88c4f841b1b3c1934bda59827 (diff) |
Always show error messages generated by dlopen().
As this would generate a lot of false positives when trying to load
plugins from $HOME/.compiz/plugins, call stat() on the plugin first in
order to see if it's openable.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/plugin.c b/src/plugin.c index 5720535e..e3f0d258 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -28,6 +28,9 @@ #include <string.h> #include <dlfcn.h> #include <dirent.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> #include <compiz-core.h> @@ -145,8 +148,10 @@ dlloaderLoadPlugin (CompPlugin *p, const char *path, const char *name) { - char *file; - void *dlhand; + char *file; + void *dlhand; + struct stat fileInfo; + Bool loaded = FALSE; file = malloc ((path ? strlen (path) : 0) + strlen (name) + 8); if (!file) @@ -157,6 +162,13 @@ dlloaderLoadPlugin (CompPlugin *p, else sprintf (file, "lib%s.so", name); + if (stat (file, &fileInfo) != 0) + { + /* file not present - try core plugin or fail */ + free (file); + return cloaderLoadPlugin (p, path, name); + } + dlhand = dlopen (file, RTLD_LAZY); if (dlhand) { @@ -165,8 +177,8 @@ dlloaderLoadPlugin (CompPlugin *p, dlerror (); - getInfo = (PluginGetInfoProc) - dlsym (dlhand, "getCompPluginInfo20070830"); + getInfo = (PluginGetInfoProc) dlsym (dlhand, + "getCompPluginInfo20070830"); error = dlerror (); if (error) @@ -184,30 +196,29 @@ dlloaderLoadPlugin (CompPlugin *p, compLogMessage ("core", CompLogLevelError, "Couldn't get vtable from '%s' plugin", file); - - dlclose (dlhand); - free (file); - - return FALSE; } - } - else - { - dlclose (dlhand); - free (file); - - return FALSE; + else + { + loaded = TRUE; + } } } else { - free (file); - - return cloaderLoadPlugin (p, path, name); + compLogMessage ("core", CompLogLevelError, + "Couldn't load plugin '%s' : %s", file, dlerror ()); } free (file); + if (!loaded) + { + if (dlhand) + dlclose (dlhand); + + return FALSE; + } + p->devPrivate.ptr = dlhand; p->devType = "dlloader"; |