From 6e7eb1e19a333d57b03605be3573f4e8bfd3a4cb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 2 Nov 2023 11:19:37 +0000 Subject: [PATCH] portal, session-helper: Save original environment and use it for child Otherwise, the child process will inherit GIO_USE_VFS=local, breaking its ability to use GVfs and other GIO plugin interfaces. Resolves: https://github.com/flatpak/flatpak/issues/5567 Signed-off-by: Simon McVittie --- portal/flatpak-portal.c | 8 +++++++- session-helper/flatpak-session-helper.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/portal/flatpak-portal.c b/portal/flatpak-portal.c index 2fcbd6a9..5ba8ec76 100644 --- a/portal/flatpak-portal.c +++ b/portal/flatpak-portal.c @@ -63,6 +63,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (PortalFlatpakUpdateMonitorSkeleton, g_object_unre /* Should be roughly 2 seconds */ #define CHILD_STATUS_CHECK_ATTEMPTS 20 +static GStrv original_environ = NULL; static GHashTable *client_pid_data_hash = NULL; static GDBusConnection *session_bus = NULL; static GNetworkMonitor *network_monitor = NULL; @@ -1042,7 +1043,7 @@ handle_spawn (PortalFlatpak *object, if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { g_warning ("Environment for \"flatpak run\" was not found, falling back to current environment"); - env = g_get_environ (); + env = g_strdupv (original_environ); } else { @@ -3025,6 +3026,10 @@ main (int argc, { NULL } }; + /* Save the enviroment before changing anything, so that subprocesses + * can get the unchanged version */ + original_environ = g_get_environ (); + setlocale (LC_ALL, ""); g_setenv ("GIO_USE_VFS", "local", TRUE); @@ -3127,5 +3132,6 @@ main (int argc, main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); + g_strfreev (original_environ); return 0; } diff --git a/session-helper/flatpak-session-helper.c b/session-helper/flatpak-session-helper.c index 40cb7bdc..a04eb9af 100644 --- a/session-helper/flatpak-session-helper.c +++ b/session-helper/flatpak-session-helper.c @@ -32,6 +32,7 @@ #include "flatpak-session-helper.h" #include "flatpak-utils-base-private.h" +static GStrv original_environ = NULL; static char *monitor_dir; static char *p11_kit_server_socket_path; static int p11_kit_server_pid = 0; @@ -310,7 +311,7 @@ handle_host_command (FlatpakDevelopment *object, env = g_strdupv (empty); } else - env = g_get_environ (); + env = g_strdupv (original_environ); n_envs = g_variant_n_children (arg_envs); for (i = 0; i < n_envs; i++) @@ -783,6 +784,10 @@ main (int argc, m_localtime = NULL; struct sigaction action; + /* Save the enviroment before changing anything, so that subprocesses + * can get the unchanged version */ + original_environ = g_get_environ (); + atexit (do_atexit); memset (&action, 0, sizeof (struct sigaction)); @@ -880,5 +885,6 @@ main (int argc, g_bus_unown_name (owner_id); + g_strfreev (original_environ); return 0; }