Make alsapid work when libasound is loaded with dlopen(). Fix for #180
when alsapid is preloaded libasound is not loaded yet for some unknown reason, late call to dlvsym() fails as well, at least for mididings (python loads _mididings.so that implicitly loads libasound.so) this changeset implements the late symbol lookup, because it makes the code smaller the actual fix is to LD_PRELOAD libasound.so as well
This commit is contained in:
parent
cd3c2e4af4
commit
60aaa492db
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
* LADI Session Handler (ladish)
|
* LADI Session Handler (ladish)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
|
* Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
|
||||||
*
|
*
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* This file contains implementation of the libasound LD_PRELOAD-ed alsapid library
|
* This file contains implementation of the libasound LD_PRELOAD-ed alsapid library
|
||||||
|
@ -76,23 +76,15 @@ static int (* real_snd_seq_close)(snd_seq_t * handle);
|
||||||
//static int (* real_snd_seq_create_port)(snd_seq_t * handle, snd_seq_port_info_t * info);
|
//static int (* real_snd_seq_create_port)(snd_seq_t * handle, snd_seq_port_info_t * info);
|
||||||
//static int (* real_snd_seq_create_simple_port)(snd_seq_t * seq, const char * name, unsigned int caps, unsigned int type);
|
//static int (* real_snd_seq_create_simple_port)(snd_seq_t * seq, const char * name, unsigned int caps, unsigned int type);
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) init(void);
|
|
||||||
|
|
||||||
/* Library constructor */
|
|
||||||
void init(void)
|
|
||||||
{
|
|
||||||
// real_snd_seq_open = dlvsym(RTLD_NEXT, "snd_seq_open", API_VERSION);
|
|
||||||
real_snd_seq_set_client_name = dlvsym(RTLD_NEXT, "snd_seq_set_client_name", API_VERSION);
|
|
||||||
real_snd_seq_close = dlvsym(RTLD_NEXT, "snd_seq_close", API_VERSION);
|
|
||||||
// real_snd_seq_create_port = dlvsym(RTLD_NEXT, "snd_seq_create_port", API_VERSION);
|
|
||||||
// real_snd_seq_create_simple_port = dlvsym(RTLD_NEXT, "snd_seq_create_simple_port", API_VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CHECK_FUNC(func) \
|
#define CHECK_FUNC(func) \
|
||||||
if (real_ ## func == NULL) \
|
if (real_ ## func == NULL) \
|
||||||
{ \
|
{ \
|
||||||
fprintf(stderr, "dlvsym(\"" #func "\", \""API_VERSION"\") failed.\n"); \
|
real_ ## func = dlvsym(RTLD_NEXT, #func, API_VERSION); \
|
||||||
return -1; \
|
if (real_ ## func == NULL) \
|
||||||
|
{ \
|
||||||
|
fprintf(stderr, "dlvsym(\""#func"\", \""API_VERSION"\") failed. %s\n", dlerror()); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -484,6 +484,8 @@ loader_run(void)
|
||||||
loader_childs_bury();
|
loader_childs_bury();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LD_PRELOAD_ADD "libalsapid.so libasound.so"
|
||||||
|
|
||||||
static void set_ldpreload(void)
|
static void set_ldpreload(void)
|
||||||
{
|
{
|
||||||
const char * old;
|
const char * old;
|
||||||
|
@ -492,7 +494,7 @@ static void set_ldpreload(void)
|
||||||
old = getenv("LD_PRELOAD");
|
old = getenv("LD_PRELOAD");
|
||||||
if (old != NULL)
|
if (old != NULL)
|
||||||
{
|
{
|
||||||
new = catdup3("libalsapid.so", " ", old);
|
new = catdup3(LD_PRELOAD_ADD, " ", old);
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Memory allocation failure. Cannot hook libalsapid.so through LD_PRELOAD.\n");
|
fprintf(stderr, "Memory allocation failure. Cannot hook libalsapid.so through LD_PRELOAD.\n");
|
||||||
|
@ -501,7 +503,7 @@ static void set_ldpreload(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new = "libalsapid.so";
|
new = LD_PRELOAD_ADD;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("LD_PRELOAD set to \"%s\"\n", new);
|
printf("LD_PRELOAD set to \"%s\"\n", new);
|
||||||
|
|
Loading…
Reference in New Issue