Skip to content

Commit 48fbb20

Browse files
osspd.c: Fix PulseAudio devices failing to open in ALSA slave
"XDG_RUNTIME_DIR" points to the directory that contains PulseAudio's socket.
1 parent c65ff1f commit 48fbb20

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

osspd.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,12 @@ static void put_os(struct ossp_stream *os)
11261126

11271127
static void set_extra_env(const pid_t pid)
11281128
{
1129+
const char *target_vars[] = {
1130+
"DISPLAY=", // Display manager
1131+
"PULSE_", // PulseAudio
1132+
"XDG_RUNTIME_DIR=" // Audio servers
1133+
};
1134+
11291135
char *line = NULL;
11301136
FILE *file;
11311137
size_t size;
@@ -1138,24 +1144,17 @@ static void set_extra_env(const pid_t pid)
11381144
if (!file)
11391145
return;
11401146

1141-
/*
1142-
* Copy all PULSE variables and DISPLAY so that
1143-
* ssh -X remotehost 'mplayer -ao oss' will work.
1144-
*/
11451147
while ((len = getdelim(&line, &size, '\0', file)) != -1) {
1146-
char *sign = NULL;
1148+
for (uint8_t i = 0; i < ARRAY_SIZE(target_vars); ++i) {
1149+
char *sign;
11471150

1148-
if (len <= 6)
1149-
continue;
1150-
1151-
if (strncmp(line, "PULSE_", 6) == 0)
1152-
sign = strchr(line, '=');
1153-
else if (len >= 8 && strncmp(line, "DISPLAY=", 8) == 0)
1154-
sign = line + 7;
1151+
if (strncmp(line, target_vars[i], strlen(target_vars[i])) != 0)
1152+
continue;
11551153

1156-
if (sign) {
1157-
*sign = '\0';
1158-
setenv(line, sign + 1, 1);
1154+
if ((sign = strchr(line, '='))) {
1155+
*sign = '\0';
1156+
setenv(line, sign + 1, 1);
1157+
}
11591158
}
11601159
}
11611160

0 commit comments

Comments
 (0)