From e313fe1b3d0d9f9945c41c151d72edbe9cf1ec54 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 18:25:40 +0000 Subject: tag modules that may only be loaded once at most especially, and enforce that in the module loader git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index dce91a71..e1680de5 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -46,6 +46,7 @@ #define PA_SYMBOL_INIT "pa__init" #define PA_SYMBOL_DONE "pa__done" +#define PA_SYMBOL_LOAD_ONCE "pa__load_once" #define UNLOAD_POLL_TIME 2 @@ -66,6 +67,7 @@ static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { pa_module *m = NULL; + pa_bool_t (*load_once)(void); pa_assert(c); pa_assert(name); @@ -82,6 +84,22 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { goto fail; } + if ((load_once = (pa_bool_t (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) { + + if (load_once()) { + pa_module *i; + uint32_t idx; + /* OK, the module only wants to be loaded once, let's make sure it is */ + + for (i = pa_idxset_first(c->modules, &idx); i; i = pa_idxset_next(c->modules, &idx)) { + if (strcmp(name, i->name) == 0) { + pa_log("Module \"%s\" should be loaded once at most. Refusing to load.", name); + goto fail; + } + } + } + } + if (!(m->init = (int (*)(pa_module*_m)) pa_load_sym(m->dl, name, PA_SYMBOL_INIT))) { pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name); goto fail; -- cgit