Bug 70 - instrument editor plugins do not load (+fix)
Summary: instrument editor plugins do not load (+fix)
Alias: None
Product: LinuxSampler
Classification: Unclassified
Component: other (show other bugs)
Version: 0.5.1
Hardware: PC Linux
: P2 normal
Assignee: Christian Schoenebeck
Depends on:
Reported: 2007-12-29 19:35 CET by Ronald Baljeu
Modified: 2008-11-30 13:35 CET (History)
0 users

See Also:

fix (1.57 KB, patch)
2007-12-29 19:42 CET, Ronald Baljeu

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Baljeu 2007-12-29 19:35:43 CET
I was trying to launch gigedit from qsampler and it did not work.
Linuxsampler did not load the gigedit plugin.

After some digging in the source I found that Linuxsampler attempts
to check whether the plugin is a regular file. This check fails, because
it uses the d_type field of the dirent struct (as returned by readdir()).
Apparently this d_type field does not work as expected.
The manual of readdir() states that the use of this field is not portable.

I'm not a c++ expert, but here is a workaround using lstat().
Note that because of the autowrapping some unintentional linebreaks
may have been inserted in the patch below.


--- src/plugins/InstrumentEditorFactory.cpp.orig        2007-12-29
18:38:18.000000000 +0100
+++ src/plugins/InstrumentEditorFactory.cpp     2007-12-29 18:36:28.000000000 +0100
@@ -28,6 +28,9 @@
 #include <dlfcn.h>
 #include <errno.h>
 #include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <string.h>

@@ -185,16 +188,20 @@
             for (dirent* pEntry = readdir(hDir); pEntry; pEntry = readdir(hDir)) {
-                // skip entries that are not regular files
-                if (pEntry->d_type != DT_REG) continue;
                 String sPath = pEntry->d_name;
+                // make it a full qualified path
+                sPath = CONFIG_PLUGIN_DIR + ("/" + sPath);
+                // skip entries that are not regular files
+                struct stat sPath_stat;
+                if (lstat(sPath.c_str(), &sPath_stat) != 0 ||
+                   (sPath_stat.st_mode & S_IFMT) != S_IFREG)
+                   continue;
                 // skip files that are not .so files
-                if (
+                if (sPath.length() < 3 ||
                     sPath.substr(sPath.length() - 3) != ".so" &&
                     sPath.find(".so.") == String::npos
                 ) continue;
-                // make it a full qualified path
-                sPath = CONFIG_PLUGIN_DIR + ("/" + sPath);
                 // load the DLL (the plugins should register themselfes
                 void* pDLL = dlopen(sPath.c_str(), RTLD_NOW);
                 if (pDLL) LoadedDLLs.push_back(pDLL);
Comment 1 Ronald Baljeu 2007-12-29 19:42:40 CET
Created attachment 20 [details]

Here is the patch (again, but without wrapping :-) ).
Comment 2 Christian Schoenebeck 2007-12-29 21:36:17 CET
Yes, you are right. I assumed that field would be available on all recent 
Linux systems at least. Your patch with lstat() looks fine for Linux and OSX, 
so I just commited it to CVS.

Thanks Ronald!