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

@ -74,6 +74,7 @@ static int detect_alsa(pa_core *c, int just_one) {
char line[64], args[64];
unsigned device, subdevice;
int is_sink;
pa_module *m = NULL;
if (!fgets(line, sizeof(line), f))
break;
@ -101,7 +102,7 @@ static int detect_alsa(pa_core *c, int just_one) {
continue;
pa_snprintf(args, sizeof(args), "device_id=%u", device);
if (!pa_module_load(c, is_sink ? "module-alsa-sink" : "module-alsa-source", args))
if (pa_module_load(&m, c, is_sink ? "module-alsa-sink" : "module-alsa-source", args) < 0)
continue;
n++;
@ -136,6 +137,7 @@ static int detect_oss(pa_core *c, int just_one) {
while (!feof(f)) {
char line[256], args[64];
unsigned device;
pa_module *m = NULL;
if (!fgets(line, sizeof(line), f))
break;
@ -156,14 +158,14 @@ static int detect_oss(pa_core *c, int just_one) {
else
pa_snprintf(args, sizeof(args), "device=/dev/dsp%u", device);
if (!pa_module_load(c, "module-oss", args))
if (pa_module_load(&m, c, "module-oss", args) < 0)
continue;
} else if (sscanf(line, "pcm%u: ", &device) == 1) {
/* FreeBSD support, the devices are named /dev/dsp0.0, dsp0.1 and so on */
pa_snprintf(args, sizeof(args), "device=/dev/dsp%u.0", device);
if (!pa_module_load(c, "module-oss", args))
if (pa_module_load(&m, c, "module-oss", args) < 0)
continue;
}
@ -183,6 +185,7 @@ static int detect_solaris(pa_core *c, int just_one) {
struct stat s;
const char *dev;
char args[64];
pa_module *m = NULL;
dev = getenv("AUDIODEV");
if (!dev)
@ -199,7 +202,7 @@ static int detect_solaris(pa_core *c, int just_one) {
pa_snprintf(args, sizeof(args), "device=%s", dev);
if (!pa_module_load(c, "module-solaris", args))
if (pa_module_load(&m, c, "module-solaris", args) < 0)
return 0;
return 1;
@ -208,11 +211,12 @@ static int detect_solaris(pa_core *c, int just_one) {
#ifdef OS_IS_WIN32
static int detect_waveout(pa_core *c, int just_one) {
pa_module *m = NULL;
/*
* FIXME: No point in enumerating devices until the plugin supports
* selecting anything but the first.
*/
if (!pa_module_load(c, "module-waveout", ""))
if (pa_module_load(&m, c, "module-waveout", "") < 0)
return 0;
return 1;