mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
module: Check version before loading a module
Since there's no stable API for modules, all modules need to be compiled together with the server. This version check tries to ensure that if a version mismatch happens, there will be an informative error message rather than a random crash.
This commit is contained in:
parent
05f3e8bf9a
commit
e43ca00d52
1 changed files with 17 additions and 0 deletions
|
|
@ -45,6 +45,7 @@
|
|||
#define PA_SYMBOL_LOAD_ONCE "pa__load_once"
|
||||
#define PA_SYMBOL_GET_N_USED "pa__get_n_used"
|
||||
#define PA_SYMBOL_GET_DEPRECATE "pa__get_deprecated"
|
||||
#define PA_SYMBOL_GET_VERSION "pa__get_version"
|
||||
|
||||
bool pa_module_exists(const char *name) {
|
||||
const char *paths, *state = NULL;
|
||||
|
|
@ -113,6 +114,7 @@ void pa_module_hook_connect(pa_module *m, pa_hook *hook, pa_hook_priority_t prio
|
|||
|
||||
int pa_module_load(pa_module** module, pa_core *c, const char *name, const char *argument) {
|
||||
pa_module *m = NULL;
|
||||
const char *(*get_version)(void);
|
||||
bool (*load_once)(void);
|
||||
const char* (*get_deprecated)(void);
|
||||
pa_modinfo *mi;
|
||||
|
|
@ -147,6 +149,21 @@ int pa_module_load(pa_module** module, pa_core *c, const char *name, const char
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if ((get_version = (const char *(*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_GET_VERSION))) {
|
||||
const char *version = get_version();
|
||||
|
||||
if (!pa_safe_streq(version, PACKAGE_VERSION)) {
|
||||
pa_log("Module \"%s\" version (%s) doesn't match the expected version (%s).",
|
||||
name, pa_strnull(version), PACKAGE_VERSION);
|
||||
errcode = -PA_ERR_IO;
|
||||
goto fail;
|
||||
}
|
||||
} else {
|
||||
pa_log("Symbol \"%s\" not found in module \"%s\".", PA_SYMBOL_GET_VERSION, name);
|
||||
errcode = -PA_ERR_IO;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((load_once = (bool (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) {
|
||||
|
||||
m->load_once = load_once();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue