@@ -233,43 +233,49 @@ static inline const char *split_walk(const char *str, const char *delimiter, siz
233233 return s ;
234234}
235235
236- static int load_ladspa_plugin ( struct plugin * impl , const char * path )
236+ static void make_search_paths ( const char * * path , const char * * search_dirs )
237237{
238- int res = - ENOENT ;
238+ const char * p ;
239+
240+ while ((p = strstr (* path , "../" )) != NULL )
241+ * path = p + 3 ;
239242
240- if ( path [ 0 ] != '/' ) {
241- const char * search_dirs , * p , * state = NULL ;
242- char filename [ PATH_MAX ] ;
243- size_t len ;
243+ * search_dirs = getenv ( "LADSPA_PATH" );
244+ if (! * search_dirs )
245+ * search_dirs = "/usr/lib64/ladspa:/usr/lib/ladspa:" LIBDIR ;
246+ }
244247
245- search_dirs = getenv ("LADSPA_PATH" );
246- if (!search_dirs )
247- search_dirs = "/usr/lib64/ladspa:/usr/lib/ladspa:" LIBDIR ;
248+ static int load_ladspa_plugin (struct plugin * impl , const char * path , const char * search_dirs )
249+ {
250+ int res = - ENOENT ;
251+ const char * p , * state = NULL ;
252+ char filename [PATH_MAX ];
253+ size_t len ;
248254
249- /*
250- * set the errno for the case when `ladspa_handle_load_by_path()`
251- * is never called, which can only happen if the supplied
252- * LADSPA_PATH contains too long paths
253- */
254- res = - ENAMETOOLONG ;
255+ /*
256+ * set the errno for the case when `ladspa_handle_load_by_path()`
257+ * is never called, which can only happen if the supplied
258+ * LADSPA_PATH contains too long paths
259+ */
260+ res = - ENAMETOOLONG ;
255261
256- while ((p = split_walk (search_dirs , ":" , & len , & state ))) {
257- int namelen ;
262+ while ((p = split_walk (search_dirs , ":" , & len , & state ))) {
263+ int namelen ;
258264
259- if (len >= sizeof (filename ))
260- continue ;
265+ if (len >= sizeof (filename ))
266+ continue ;
261267
268+ if (strncmp (path , p , len ) == 0 )
269+ namelen = snprintf (filename , sizeof (filename ), "%s" , path );
270+ else
262271 namelen = snprintf (filename , sizeof (filename ), "%.*s/%s.so" , (int ) len , p , path );
263- if (namelen < 0 || (size_t ) namelen >= sizeof (filename ))
264- continue ;
265272
266- res = ladspa_handle_load_by_path (impl , filename );
267- if (res >= 0 )
268- break ;
269- }
270- }
271- else {
272- res = ladspa_handle_load_by_path (impl , path );
273+ if (namelen < 0 || (size_t ) namelen >= sizeof (filename ))
274+ continue ;
275+
276+ res = ladspa_handle_load_by_path (impl , filename );
277+ if (res >= 0 )
278+ break ;
273279 }
274280 return res ;
275281}
@@ -317,7 +323,7 @@ impl_init(const struct spa_handle_factory *factory,
317323 struct plugin * impl ;
318324 uint32_t i ;
319325 int res ;
320- const char * path = NULL ;
326+ const char * path = NULL , * search_dirs ;
321327
322328 handle -> get_interface = impl_get_interface ;
323329 handle -> clear = impl_clear ;
@@ -335,9 +341,11 @@ impl_init(const struct spa_handle_factory *factory,
335341 if (path == NULL )
336342 return - EINVAL ;
337343
338- if ((res = load_ladspa_plugin (impl , path )) < 0 ) {
339- spa_log_error (impl -> log , "failed to load plugin '%s': %s" ,
340- path , spa_strerror (res ));
344+ make_search_paths (& path , & search_dirs );
345+
346+ if ((res = load_ladspa_plugin (impl , path , search_dirs )) < 0 ) {
347+ spa_log_error (impl -> log , "failed to load plugin '%s' in '%s': %s" ,
348+ path , search_dirs , spa_strerror (res ));
341349 return res ;
342350 }
343351
0 commit comments