]> code.delx.au - pulseaudio/commitdiff
fix implementation of bind now ltdl loader for libtool 2.2
authorLennart Poettering <lennart@poettering.net>
Tue, 16 Dec 2008 18:11:16 +0000 (19:11 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Dec 2008 18:11:16 +0000 (19:11 +0100)
src/daemon/ltdl-bind-now.c

index 2d80fc7a5f806fdb48e3fb1b20271813ced5648f..8444cfb499dd06a4d4d70056d5d30e2fd05538c0 100644 (file)
@@ -1,7 +1,7 @@
 /***
   This file is part of PulseAudio.
 
-  Copyright 2004-2006 Lennart Poettering
+  Copyright 2004-2008 Lennart Poettering
   Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
@@ -39,8 +39,6 @@
 #include <pulse/i18n.h>
 
 #include <pulsecore/macro.h>
-#include <pulsecore/mutex.h>
-#include <pulsecore/thread.h>
 #include <pulsecore/log.h>
 
 #include "ltdl-bind-now.h"
   to set $LT_BIND_NOW before starting the pulsaudio binary.
 */
 
-static lt_module bind_now_open(lt_user_data d, const char *fname, lt_dladvise advise)
-{
+static lt_module bind_now_open(lt_user_data d, const char *fname, lt_dladvise advise) {
     lt_module m;
 
     pa_assert(fname);
 
     if (!(m = dlopen(fname, PA_BIND_NOW))) {
-#ifdef HAVE_LT_DLMUTEX_REGISTER
-        libtool_set_error(dlerror());
-#endif
+        lt_dlseterror(LT_ERROR_CANNOT_OPEN);
         return NULL;
     }
 
@@ -88,9 +83,7 @@ static int bind_now_close(lt_user_data d, lt_module m) {
     pa_assert(m);
 
     if (dlclose(m) != 0){
-#ifdef HAVE_LT_DLMUTEX_REGISTER
-        libtool_set_error(dlerror());
-#endif
+        lt_dlseterror(LT_ERROR_CANNOT_CLOSE);
         return 1;
     }
 
@@ -104,49 +97,61 @@ static lt_ptr bind_now_find_sym(lt_user_data d, lt_module m, const char *symbol)
     pa_assert(symbol);
 
     if (!(ptr = dlsym(m, symbol))) {
-#ifdef HAVE_LT_DLMUTEX_REGISTER
-        libtool_set_error(dlerror());
-#endif
+        lt_dlseterror(LT_ERROR_SYMBOL_NOT_FOUND);
         return NULL;
     }
 
     return ptr;
 }
 
+static lt_dlvtable *bindnow_loader = NULL;
 #endif
 
 void pa_ltdl_init(void) {
 
 #ifdef PA_BIND_NOW
-    static const lt_dlvtable *dlopen_loader;
-    static lt_dlvtable bindnow_loader;
+    const lt_dlvtable *dlopen_loader;
 #endif
 
     pa_assert_se(lt_dlinit() == 0);
 
 #ifdef PA_BIND_NOW
     /* Already initialised */
-    if (dlopen_loader)
+    if (bindnow_loader)
+        return;
+
+    if (!(dlopen_loader = lt_dlloader_find((char*) "lt_dlopen"))) {
+        pa_log_warn(_("Failed to find original lt_dlopen loader."));
         return;
+    }
 
-    if (!(dlopen_loader = lt_dlloader_find("dlopen"))) {
-        pa_log_warn(_("Failed to find original dlopen loader."));
+    if (!(bindnow_loader = malloc(sizeof(lt_dlvtable)))) {
+        pa_log_error(_("Failed to allocate new dl loader."));
         return;
     }
 
-    memcpy(&bindnow_loader, dlopen_loader, sizeof(bindnow_loader));
-    bindnow_loader.name = "bind-now-loader";
-    bindnow_loader.module_open = bind_now_open;
-    bindnow_loader.module_close = bind_now_close;
-    bindnow_loader.find_sym = bind_now_find_sym;
-    bindnow_loader.priority = LT_DLLOADER_PREPEND;
+    memcpy(bindnow_loader, dlopen_loader, sizeof(*bindnow_loader));
+    bindnow_loader->name = "bind-now-loader";
+    bindnow_loader->module_open = bind_now_open;
+    bindnow_loader->module_close = bind_now_close;
+    bindnow_loader->find_sym = bind_now_find_sym;
+    bindnow_loader->priority = LT_DLLOADER_PREPEND;
 
     /* Add our BIND_NOW loader as the default module loader. */
-    if (lt_dlloader_add(&bindnow_loader) != 0)
+    if (lt_dlloader_add(bindnow_loader) != 0) {
         pa_log_warn(_("Failed to add bind-now-loader."));
+        free(bindnow_loader);
+        bindnow_loader = NULL;
+    }
 #endif
 }
 
 void pa_ltdl_done(void) {
     pa_assert_se(lt_dlexit() == 0);
+
+#ifdef PA_BIND_NOW
+    /* lt_dlexit() will free our loader vtable, hence reset our
+     * pointer to it here */
+    bindnow_loader = NULL;
+#endif
 }