]> git.sesse.net Git - vlc/blobdiff - src/misc/plugins.c
. now we only try to open plugins which are existing files
[vlc] / src / misc / plugins.c
index f4179659d6ea639536bf51b40851d48f1e3c8b87..3cc156dcca33a96b0c04f590cc038b8451068b8b 100644 (file)
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                            /* strerror() */
 #include <errno.h>                                                 /* ENOMEM */
+#include <sys/types.h>                                               /* open */
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>                                                 /* close */
 
 #if defined(HAVE_DLFCN_H)                                /* Linux, BSD, Hurd */
 #include <dlfcn.h>                           /* dlopen(), dlsym(), dlclose() */
@@ -107,6 +111,7 @@ void bank_Init( plugin_bank_t * p_bank )
     /* Audio pluins */
     SEEK_PLUGIN( "dsp" );
     SEEK_PLUGIN( "esd" );
+    SEEK_PLUGIN( "alsa" );
     
     /* Dummy plugin */
     SEEK_PLUGIN( "dummy" );
@@ -134,7 +139,7 @@ void bank_Destroy( plugin_bank_t * p_bank )
 
 char * TestPlugin ( plugin_id_t *p_plugin_id, char * psz_name )
 {
-    int i_count, i_length;
+    int i_count, i_length, i_fd;
     char * psz_plugin;
     char * psz_plugin_path[ ] =
     {
@@ -153,7 +158,7 @@ char * TestPlugin ( plugin_id_t *p_plugin_id, char * psz_name )
         
         psz_program_path = beos_GetProgramPath();
         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) +
-                             strlen(psz_program_path) + i_length + 5 );
+                             strlen(psz_program_path) + i_length + 6 );
         sprintf( psz_plugin, "%s/%s/%s.so", psz_program_path,
                  psz_plugin_path[i_count], psz_name );        
 
@@ -162,23 +167,30 @@ char * TestPlugin ( plugin_id_t *p_plugin_id, char * psz_name )
         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + i_length + 5 );
         sprintf( psz_plugin, "%s/%s.so", psz_plugin_path[i_count], psz_name );
 
+        /* Try to open the plugin before dlopen()ing it. */
+        i_fd = open( psz_plugin, O_RDONLY );
+        if( i_fd == -1 )
+        {
+            free( psz_plugin );
+            continue;
+        }
+        close( i_fd );
+        
         *p_plugin_id = dlopen( psz_plugin, RTLD_NOW | RTLD_GLOBAL );
 #endif
 
 #ifdef SYS_BEOS
         if( *p_plugin_id >= 0 )
 #else
-       if( *p_plugin_id != NULL )
+        if( *p_plugin_id != NULL )
 #endif
         {
             /* plugin successfuly dlopened */
             return( psz_plugin );
         }
+
 #ifndef SYS_BEOS
-        else
-        {
-            intf_DbgMsg( "%s\n", dlerror() );
-        }
+        intf_WarnMsg( 1, "Plugin %s failed: %s\n", psz_plugin, dlerror() );
 #endif
 
         free( psz_plugin );