From 1a39648f0f85f7b0f2e50a8cd7746c64c1abcc66 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Wed, 14 Apr 2021 12:16:00 +0100 Subject: [PATCH] pv-wrap: Factor out get_subsandbox_adverb() Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/wrap-flatpak.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pressure-vessel/wrap-flatpak.c b/pressure-vessel/wrap-flatpak.c index 2601131bd..cb2e86e4a 100644 --- a/pressure-vessel/wrap-flatpak.c +++ b/pressure-vessel/wrap-flatpak.c @@ -24,6 +24,9 @@ #include "flatpak-run-private.h" #include "utils.h" +#define FLATPAK_PORTAL_BUS_NAME "org.freedesktop.portal.Flatpak" +#define FLATPAK_SESSION_HELPER_BUS_NAME "org.freedesktop.Flatpak" + static gboolean check_launch_on_host (const char *launch_executable, GError **error) @@ -34,7 +37,7 @@ check_launch_on_host (const char *launch_executable, const char *test_argv[] = { NULL, - "--bus-name=org.freedesktop.Flatpak", + "--bus-name=" FLATPAK_SESSION_HELPER_BUS_NAME, "--", "true", NULL @@ -72,6 +75,21 @@ check_launch_on_host (const char *launch_executable, return TRUE; } +static FlatpakBwrap * +get_subsandbox_adverb (const char *launch_executable) +{ + FlatpakBwrap *ret = flatpak_bwrap_new (flatpak_bwrap_empty_env); + + flatpak_bwrap_add_arg (ret, launch_executable); + /* Tell pressure-vessel-launch to send its whole environment + * to the subsandbox, except for the parts that we edit later. + * This effectively matches bwrap's behaviour. */ + flatpak_bwrap_add_arg (ret, "--pass-env-matching=*"); + flatpak_bwrap_add_arg (ret, "--bus-name=" FLATPAK_PORTAL_BUS_NAME); + + return ret; +} + /* * pv_wrap_check_flatpak: * @tools_dir: Path to .../pressure-vessel/bin/ @@ -139,15 +157,7 @@ pv_wrap_check_flatpak (const char *tools_dir, { g_warning ("Assuming your version of Flatpak contains unmerged " "changes (#4018, #4125, #4126, #4093)"); - /* Use a sub-sandbox */ - subsandbox = flatpak_bwrap_new (flatpak_bwrap_empty_env); - flatpak_bwrap_add_arg (subsandbox, launch_executable); - /* Tell pressure-vessel-launch to send its whole environment - * to the subsandbox, except for the parts that we edit later. - * This effectively matches bwrap's behaviour. */ - flatpak_bwrap_add_arg (subsandbox, "--pass-env-matching=*"); - flatpak_bwrap_add_arg (subsandbox, - "--bus-name=org.freedesktop.portal.Flatpak"); + subsandbox = get_subsandbox_adverb (launch_executable); } /* Also deliberately not documented */ else if (g_getenv ("PRESSURE_VESSEL_FLATPAK_SANDBOX_ESCAPE") != NULL) -- GitLab