cli-command: don't exit on "module already loaded" errors

Some modules may only be loaded once, and trying to load them
twice from default.pa makes PulseAudio startup fail. While that could
be considered a user error, it's nicer to not be so strict. It's not
necessarily easy to figure what went wrong, if for example the user
plays with RAOP and adds module-raop-discover to default.pa, which first
works fine, but suddenly stops working when the user at some point
enables RAOP support in paprefs. Enabling RAOP in paprefs makes
module-gconf load the module too, so the module gets loaded twice.

This patch adds a way to differentiate module load errors, and
make cli-command ignore the error when the module is already
loaded.
This commit is contained in:
Colin Leroy 2017-08-26 11:21:15 +02:00 committed by Tanu Kaskinen
parent 1a66715320
commit f0dfddead3
23 changed files with 62 additions and 36 deletions

View file

@ -421,6 +421,8 @@ static int pa_cli_command_info(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, bool
static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail) {
const char *name;
pa_error_code_t err;
pa_module *m = NULL;
pa_core_assert_ref(c);
pa_assert(t);
@ -432,9 +434,13 @@ static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, bool
return -1;
}
if (!pa_module_load(c, name, pa_tokenizer_get(t, 2))) {
pa_strbuf_puts(buf, "Module load failed.\n");
return -1;
if ((err = pa_module_load(&m, c, name, pa_tokenizer_get(t, 2))) < 0) {
if (err == PA_ERR_EXIST) {
pa_strbuf_puts(buf, "Module already loaded; ignoring.\n");
} else {
pa_strbuf_puts(buf, "Module load failed.\n");
return -1;
}
}
return 0;