1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
| | From 5bc1a490fa68187bce15eb9e8305b88ff6fbdbe5 Mon Sep 17 00:00:00 2001
From: Leo Famulari <leo@famulari.name>
Date: Mon, 27 Apr 2020 13:09:54 -0400
Subject: [PATCH] Search for plugins in $GUIX_ALSA_PLUGIN_DIRS.
* src/control/control.c (snd_ctl_open_conf): If ALSA plugins cannot be found in
the default locations, look in the directories in $GUIX_ALSA_PLUGIN_DIRS.
* src/dlmisc.c (snd_dlopen): Likewise.
* src/pcm/pcm.c (snd_pcm_open_conf): Likewise.
---
src/control/control.c | 35 ++++++++++++++++++++++++++++++++++-
src/dlmisc.c | 26 +++++++++++++++++++++-----
src/pcm/pcm.c | 35 ++++++++++++++++++++++++++++++++++-
3 files changed, 89 insertions(+), 7 deletions(-)
diff --git a/src/control/control.c b/src/control/control.c
index 27f42135..108a560b 100644
--- a/src/control/control.c
+++ b/src/control/control.c
@@ -1342,8 +1342,41 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
err = -ENOMEM;
goto _err;
}
+ sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
+ if (access(buf1, F_OK) != 0) {
+ const char *plugindirs = getenv("GUIX_ALSA_PLUGIN_DIRS");
+
+ if (plugindirs) {
+ char *plugindirs_copy = alloca(strlen(plugindirs) + 1);
+ if (plugindirs_copy == NULL) {
+ err = -ENOMEM;
+ goto _err;
+ }
+ strcpy(plugindirs_copy, plugindirs);
+ char *saveptr;
+ while (1) {
+ char *dir_tok = strtok_r(plugindirs_copy, ":", &saveptr);
+ if (dir_tok == NULL)
+ break;
+ char *so_file = malloc(strlen(dir_tok) + 1 + strlen(str) + 32);
+ if (so_file == NULL) {
+ err = -ENOMEM;
+ goto _err;
+ }
+
+ sprintf(so_file, "%s/libasound_module_ctl_%s.so", dir_tok, str);
+
+ if (access(so_file, F_OK) == 0) {
+ buf1 = so_file;
+ break;
+ } else {
+ free (so_file);
+ }
+ plugindirs_copy = NULL;
+ }
+ }
+ }
lib = buf1;
- sprintf(buf1, "%s/libasound_module_ctl_%s.so", ALSA_PLUGIN_DIR, str);
}
}
#ifndef PIC
diff --git a/src/dlmisc.c b/src/dlmisc.c
index 8c8f3ff7..b115447c 100644
--- a/src/dlmisc.c
+++ b/src/dlmisc.c
@@ -82,11 +82,27 @@ void *snd_dlopen(const char *name, int mode, char *errbuf, size_t errbuflen)
char *filename = NULL;
if (name && name[0] != '/') {
- filename = alloca(sizeof(ALSA_PLUGIN_DIR) + 1 + strlen(name) + 1);
- if (filename) {
- strcpy(filename, ALSA_PLUGIN_DIR);
- strcat(filename, "/");
- strcat(filename, name);
+ const char *plugindirs = getenv("GUIX_ALSA_PLUGIN_DIRS");
+ if (plugindirs) {
+ char *plugindirs_copy = alloca(strlen(plugindirs) + 1);
+ if (plugindirs_copy == NULL)
+ goto errpath;
+ strcpy(plugindirs_copy, plugindirs);
+ char *saveptr;
+ while (1) {
+ char *dir_tok = strtok_r(plugindirs_copy, ":", &saveptr);
+ if (dir_tok == NULL)
+ break;
+ char *sofilename = malloc(strlen(dir_tok) + 1 + strlen(name) + 1);
+ sprintf(sofilename, "%s/%s" ,dir_tok, name);
+ if (access(sofilename, F_OK) == 0) {
+ filename = sofilename;
+ break;
+ } else {
+ free (sofilename);
+ }
+ plugindirs_copy = NULL;
+ }
handle = dlopen(filename, mode);
if (!handle) {
/* if the filename exists and cannot be opened */
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 1064044c..90ba00ac 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -2578,8 +2578,41 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
err = -ENOMEM;
goto _err;
}
- lib = buf1;
sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
+ if (access(buf1, F_OK) != 0) {
+ const char *plugindirs = getenv("GUIX_ALSA_PLUGIN_DIRS");
+
+ if (plugindirs) {
+ char *plugindirs_copy = alloca(strlen(plugindirs) + 1);
+ if (plugindirs_copy == NULL) {
+ err = -ENOMEM;
+ goto _err;
+ }
+ strcpy(plugindirs_copy, plugindirs);
+ char *saveptr;
+ while (1) {
+ char *dir_tok = strtok_r(plugindirs_copy, ":", &saveptr);
+ if (dir_tok == NULL)
+ break;
+ char *so_file = malloc(strlen(dir_tok) + 1 + strlen(str) + 32);
+ if (so_file == NULL) {
+ err = -ENOMEM;
+ goto _err;
+ }
+
+ sprintf(so_file, "%s/libasound_module_pcm_%s.so", dir_tok, str);
+
+ if (access(so_file, F_OK) == 0) {
+ buf1 = so_file;
+ break;
+ } else {
+ free (so_file);
+ }
+ plugindirs_copy = NULL;
+ }
+ }
+ }
+ lib = buf1;
}
}
#ifndef PIC
--
2.26.2
|