From 8d7312b1713fd19e844ad4a94741cec399ecee9b Mon Sep 17 00:00:00 2001 From: netblue Date: Fri, 9 Oct 2015 09:33:19 -0400 Subject: PulseAudio 7.0 fix --- README.md | 10 ++++--- src/firejail/firejail.h | 3 +++ src/firejail/pulseaudio.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ src/firejail/sandbox.c | 5 ++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/firejail/pulseaudio.c diff --git a/README.md b/README.md index 5e061f0ce..62ec486e3 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,13 @@ FAQ: https://l3net.wordpress.com/projects/firejail/firejail-faq/ ### PulseAudio 7.0 -The srbchannel IPC mechanism introduced in 6.0, was enabled by default in release 7.0. +The srbchannel IPC mechanism introduced in PulseAudio 6.0, was enabled by default in release 7.0. Arch Linux users are reporting sound problems when running applications in Firejail sandbox. -The issue is still under investigation. There are two workarounds so far: +A preliminary fix was introduced on master branch. The fix disables PulseAudio shared memory functionality +in the sandbox. If you are seeing any problems, +please let us know here: https://github.com/netblue30/firejail/issues/69 + +If you are unable to update your Firejail install to the latest development version, there are two workarounds: * Running ALSA @@ -57,6 +61,4 @@ $ echo "enable-shm = no" >> client.conf ````` -If you are still having problems, join the discussion here: https://github.com/netblue30/firejail/issues/69 - diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 261821338..2dd70c7f4 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h @@ -401,5 +401,8 @@ int errno_find_name(const char *name); char *errno_find_nr(int nr); void errno_print(void); +// pulseaudio.c +void pulseaudio_init(void); + #endif diff --git a/src/firejail/pulseaudio.c b/src/firejail/pulseaudio.c new file mode 100644 index 000000000..bea0cc940 --- /dev/null +++ b/src/firejail/pulseaudio.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014, 2015 Firejail Authors + * + * This file is part of firejail project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "firejail.h" +#include +#include +#include + +// disable shm in pulse audio +void pulseaudio_init(void) { + struct stat s; + + // do we have pulseaudio in the system? + if (stat("/etc/pulse/client.conf", &s) == -1) + return; + + // crate the new user pulseaudio directory + char *pulsedir; + if (asprintf(&pulsedir, "%s/pulse", MNT_DIR) == -1) + errExit("asprintf"); + int rv = mkdir(pulsedir, S_IRWXU | S_IRWXG | S_IRWXO); + if (rv == -1) + errExit("mkdir"); + if (chown(pulsedir, getuid(), getgid()) < 0) + errExit("chown"); + if (chmod(pulsedir, 0700) < 0) + errExit("chmod"); + + // create the new client.conf file + char *pulsecfg = NULL; + if (asprintf(&pulsecfg, "%s/client.conf", pulsedir) == -1) + errExit("asprintf"); + if (copy_file("/etc/pulse/client.conf", pulsecfg)) + errExit("copy_file"); + FILE *fp = fopen(pulsecfg, "a+"); + if (!fp) + errExit("fopen"); + fprintf(fp, "\nenable-shm = no\n"); + fclose(fp); + if (chmod(pulsecfg, 0644) == -1) + errExit("chmod"); + if (chown(pulsecfg, getuid(), getgid()) == -1) + errExit("chown"); + + + // set environment + if (setenv("PULSE_CLIENTCONFIG", pulsecfg, 1) < 0) + errExit("setenv"); + + + free(pulsecfg); + free(pulsedir); +} diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c index c9146560b..eca4c2282 100644 --- a/src/firejail/sandbox.c +++ b/src/firejail/sandbox.c @@ -269,6 +269,11 @@ int sandbox(void* sandbox_arg) { //**************************** fs_proc_sys_dev_boot(); + //**************************** + // fix for pulseaudio 7.0 + //**************************** + pulseaudio_init(); + //**************************** // networking //**************************** -- cgit v1.2.3-70-g09d2