Skip to content

Commit

Permalink
Merge PR #12: osspd.c: Fix PulseAudio devices failing to open in ALSA…
Browse files Browse the repository at this point in the history
… slave
  • Loading branch information
davidebeatrici authored Sep 1, 2022
2 parents c65ff1f + 48fbb20 commit c42e426
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions osspd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,12 @@ static void put_os(struct ossp_stream *os)

static void set_extra_env(const pid_t pid)
{
const char *target_vars[] = {
"DISPLAY=", // Display manager
"PULSE_", // PulseAudio
"XDG_RUNTIME_DIR=" // Audio servers
};

char *line = NULL;
FILE *file;
size_t size;
Expand All @@ -1138,24 +1144,17 @@ static void set_extra_env(const pid_t pid)
if (!file)
return;

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

if (len <= 6)
continue;

if (strncmp(line, "PULSE_", 6) == 0)
sign = strchr(line, '=');
else if (len >= 8 && strncmp(line, "DISPLAY=", 8) == 0)
sign = line + 7;
if (strncmp(line, target_vars[i], strlen(target_vars[i])) != 0)
continue;

if (sign) {
*sign = '\0';
setenv(line, sign + 1, 1);
if ((sign = strchr(line, '='))) {
*sign = '\0';
setenv(line, sign + 1, 1);
}
}
}

Expand Down

0 comments on commit c42e426

Please sign in to comment.