summaryrefslogtreecommitdiff
path: root/src/modules/alsa/alsa-mixer.c
diff options
context:
space:
mode:
authorSimonP <simonp.git@gmail.com>2020-05-07 16:13:27 +0100
committerPulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org>2020-12-14 19:25:12 +0000
commit9b0ae8327d990584bb9a966d8d7bee6badbdb8c0 (patch)
tree84e32a289e25917cf40fcd21a22a1e658215f520 /src/modules/alsa/alsa-mixer.c
parentcb91d7a12e6be0e2c720d47d2ceca322a7b21d2c (diff)
alsa-mixer: Respect XDG base directory spec when loading path configs
Try $XDG_DATA_HOME, then $XDG_DATA_DIRS, and finally fall back to old behaviour (prefix-defined directory). core-util: Ignore non-absolute XDG base dirs These are invalid per the spec. Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/862 Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/293>
Diffstat (limited to 'src/modules/alsa/alsa-mixer.c')
-rw-r--r--src/modules/alsa/alsa-mixer.c68
1 files changed, 60 insertions, 8 deletions
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index f978f71c3..c40629712 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -2763,13 +2763,66 @@ static int path_verify(pa_alsa_path *p) {
return 0;
}
-static const char *get_default_paths_dir(void) {
+static char *get_path_config_path(const char *paths_dir, const char *fname) {
+ char *path_config_path;
+ char *dir;
+ char *data_home;
+ pa_dynarray *data_dirs;
+
+ if (paths_dir) {
+ path_config_path = pa_maybe_prefix_path(fname, paths_dir);
+ if (access(path_config_path, R_OK) == 0)
+ return path_config_path;
+ else
+ pa_xfree(path_config_path);
+ }
+
#ifdef HAVE_RUNNING_FROM_BUILD_TREE
- if (pa_run_from_build_tree())
- return PA_SRCDIR "/modules/alsa/mixer/paths/";
- else
+ if (pa_run_from_build_tree()) {
+ path_config_path = pa_maybe_prefix_path(fname, PA_SRCDIR "/modules/alsa/mixer/paths/");
+ if (access(path_config_path, R_OK) == 0)
+ return path_config_path;
+ else
+ pa_xfree(path_config_path);
+ }
#endif
- return PA_ALSA_PATHS_DIR;
+
+ if (pa_get_data_home_dir(&data_home) == 0) {
+ dir = pa_sprintf_malloc("%s" PA_PATH_SEP "alsa-mixer" PA_PATH_SEP "paths", data_home);
+ pa_xfree(data_home);
+
+ path_config_path = pa_maybe_prefix_path(fname, dir);
+ pa_xfree(dir);
+
+ if (access(path_config_path, R_OK) == 0)
+ return path_config_path;
+ else
+ pa_xfree(path_config_path);
+ }
+
+ if (pa_get_data_dirs(&data_dirs) == 0) {
+ int idx;
+ const char *n;
+
+ PA_DYNARRAY_FOREACH(n, data_dirs, idx) {
+ dir = pa_sprintf_malloc("%s" PA_PATH_SEP "alsa-mixer" PA_PATH_SEP "paths", n);
+ path_config_path = pa_maybe_prefix_path(fname, dir);
+ pa_xfree(dir);
+
+ if (access(path_config_path, R_OK) == 0) {
+ pa_dynarray_free(data_dirs);
+ return path_config_path;
+ }
+ else {
+ pa_xfree(path_config_path);
+ }
+ }
+
+ pa_dynarray_free(data_dirs);
+ }
+
+ path_config_path = pa_maybe_prefix_path(fname, PA_ALSA_PATHS_DIR);
+ return path_config_path;
}
pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa_direction_t direction) {
@@ -2827,10 +2880,9 @@ pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa
items[2].data = &p->description;
items[3].data = &mute_during_activation;
- if (!paths_dir)
- paths_dir = get_default_paths_dir();
+ fn = get_path_config_path(paths_dir, fname);
- fn = pa_maybe_prefix_path(fname, paths_dir);
+ pa_log_info("Loading path config: %s", fn);
r = pa_config_parse(fn, NULL, items, p->proplist, false, p);
pa_xfree(fn);