From: Lennart Poettering Date: Tue, 16 Dec 2008 18:11:16 +0000 (+0100) Subject: fix implementation of bind now ltdl loader for libtool 2.2 X-Git-Tag: submit/2.0-panda/20130828.192557~2549 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8fe1b683e9d373bb3475b30099593f00eaf4cff;p=profile%2Fivi%2Fpulseaudio-panda.git fix implementation of bind now ltdl loader for libtool 2.2 --- diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c index 2d80fc7..8444cfb 100644 --- a/src/daemon/ltdl-bind-now.c +++ b/src/daemon/ltdl-bind-now.c @@ -1,7 +1,7 @@ /*** This file is part of PulseAudio. - Copyright 2004-2006 Lennart Poettering + Copyright 2004-2008 Lennart Poettering Copyright 2006 Pierre Ossman for Cendio AB PulseAudio is free software; you can redistribute it and/or modify @@ -39,8 +39,6 @@ #include #include -#include -#include #include #include "ltdl-bind-now.h" @@ -67,16 +65,13 @@ 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 }