diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index 8e3c049fcb4688ffcf92d5606e8aa4d6f966e818..ae3595d86b19cb49624200730389f8af91ba7157 100644 --- a/pressure-vessel/runtime.c +++ b/pressure-vessel/runtime.c @@ -90,6 +90,7 @@ struct _PvRuntime gboolean runtime_is_just_usr; gboolean is_steamrt; gboolean is_scout; + gboolean is_flatpak_env; }; struct _PvRuntimeClass @@ -392,6 +393,8 @@ pv_runtime_init (PvRuntime *self) self->all_libc_from_provider = FALSE; self->variable_dir_fd = -1; self->mutable_sysroot_fd = -1; + self->is_flatpak_env = g_file_test ("/.flatpak-info", + G_FILE_TEST_IS_REGULAR); } static void @@ -2207,6 +2210,7 @@ bind_runtime_base (PvRuntime *self, }; static const char * const dont_bind[] = { + "/etc/asound.conf", "/etc/localtime", "/etc/machine-id", "/var/cache/ldconfig", @@ -4866,6 +4870,51 @@ pv_runtime_set_search_paths (PvRuntime *self, pv_environ_lock_env (container_env, "LD_LIBRARY_PATH", ld_library_path->str); } +gboolean +pv_runtime_use_shared_sockets (PvRuntime *self, + FlatpakBwrap *bwrap, + PvEnviron *container_env, + GError **error) +{ + if (pv_environ_is_locked (container_env, "PULSE_SERVER") + || self->is_flatpak_env) + { + /* Make the PulseAudio driver the default. + * We do this unconditionally when we are under Flatpak for parity + * with the freedesktop.org Platform. */ + const gchar *alsa_config = "pcm.!default pulse\n" + "ctl.!default pulse\n"; + + if (bwrap != NULL) + { + flatpak_bwrap_add_args_data (bwrap, "asound.conf", + alsa_config, -1, + "/etc/asound.conf", + NULL); + } + else if (self->mutable_sysroot_fd >= 0) + { + /* In a Flatpak sub-sandbox, we can rely on the fact that + * Flatpak will mount each item in our copy of the runtime's + * usr/etc/ into /etc, including some that we would normally + * skip. */ + if (!glnx_file_replace_contents_at (self->mutable_sysroot_fd, + "usr/etc/asound.conf", + (const guint8 *) alsa_config, + strlen (alsa_config), + GLNX_FILE_REPLACE_NODATASYNC, + NULL, error)) + return FALSE; + } + else + { + g_warning ("Unable to configure libasound.so.2 to use PulseAudio"); + } + } + + return TRUE; +} + static void pv_runtime_initable_iface_init (GInitableIface *iface, gpointer unused G_GNUC_UNUSED) diff --git a/pressure-vessel/runtime.h b/pressure-vessel/runtime.h index 6b3b91da926f63433f3f9b7e3fd40ef68c3ca20f..1fe178e51d1f344945c6d9092460da350706b111 100644 --- a/pressure-vessel/runtime.h +++ b/pressure-vessel/runtime.h @@ -109,4 +109,9 @@ gboolean pv_runtime_garbage_collect_legacy (const char *variable_dir, const char *runtime_base, GError **error); +gboolean pv_runtime_use_shared_sockets (PvRuntime *self, + FlatpakBwrap *bwrap, + PvEnviron *container_env, + GError **error); + G_DEFINE_AUTOPTR_CLEANUP_FUNC (PvRuntime, g_object_unref) diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c index 78c48d39869e912115ed915e75a57c0f4c6e0f97..f46a44d6bdbb1e2bf2da440754422cc7927e46cd 100644 --- a/pressure-vessel/wrap.c +++ b/pressure-vessel/wrap.c @@ -2417,20 +2417,11 @@ main (int argc, (runtime != NULL), is_flatpak_env); - if (runtime != NULL - && (pv_environ_is_locked(container_env, "PULSE_SERVER") - || is_flatpak_env)) - { - /* Make the PulseAudio driver the default. - * We do this unconditionally when we are under Flatpak for parity - * with the freedesktop.org Platform. */ - const gchar *alsa_config = "pcm.!default pulse\n" - "ctl.!default pulse\n"; - - flatpak_bwrap_add_args_data (bwrap, "99-pulseaudio-default.conf", - alsa_config, -1, - "/etc/alsa/conf.d/99-pulseaudio-default.conf", - NULL); + if (runtime != NULL) + { + if (!pv_runtime_use_shared_sockets (runtime, bwrap, container_env, + error)) + goto out; } if (is_flatpak_env)