Skip to content

Commit

Permalink
portal, session-helper: Save original environment and use it for child
Browse files Browse the repository at this point in the history
Otherwise, the child process will inherit GIO_USE_VFS=local, breaking
its ability to use GVfs and other GIO plugin interfaces.

Resolves: flatpak/flatpak#5567
Signed-off-by: Simon McVittie <[email protected]>
(cherry picked from commit 6e7eb1e)
  • Loading branch information
smcv committed Nov 14, 2023
1 parent 3ac2d52 commit 4870e6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion portal/flatpak-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -999,7 +1000,9 @@ handle_spawn (PortalFlatpak *object,
env = g_strdupv (empty);
}
else
env = g_get_environ ();
{
env = g_strdupv (original_environ);
}

if ((flatpak = g_getenv ("FLATPAK_PORTAL_MOCK_FLATPAK")) != NULL)
g_ptr_array_add (flatpak_argv, g_strdup (flatpak));
Expand Down Expand Up @@ -2994,6 +2997,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);
Expand Down Expand Up @@ -3096,5 +3103,6 @@ main (int argc,
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);

g_strfreev (original_environ);
return 0;
}
8 changes: 7 additions & 1 deletion session-helper/flatpak-session-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -880,5 +885,6 @@ main (int argc,

g_bus_unown_name (owner_id);

g_strfreev (original_environ);
return 0;
}

0 comments on commit 4870e6a

Please sign in to comment.