portal: Cleanup getting the host-like environment for flatpak-run

This commit is contained in:
Sebastian Wick committed 2026-07-27 13:51:16 +00:00
1 parent afbabdc32c
commit 21a9692718
1 file changed
+28 -24
+28 -24
View File
@@ -917,33 +917,37 @@ handle_spawn (PortalFlatpak *object,
}
}
{
static const char * const mock_run_environ[] = { "FOO=bar", NULL };
/* Pass the calling instance's run-environ as the envp for spawning
* flatpak run, so it can make host-level decisions (DISPLAY, GL drivers,
* XDG_RUNTIME_DIR, etc.) based on the original environment. This must NOT
* go into --env-fd, because run-environ is host-like and --env-fd injects
* into the sandbox payload environment.
*/
{
static const char * const mock_run_environ[] = { "FOO=bar", NULL };
if (testing)
env = g_strdupv ((GStrv) mock_run_environ);
else
env = flatpak_instance_get_run_environ (instance, &error);
if (testing)
env = g_strdupv ((GStrv) mock_run_environ);
else
env = flatpak_instance_get_run_environ (instance, &error);
if (env == NULL)
{
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_strdupv (original_environ);
}
else
{
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_INVALID_ARGS,
"Could not load environment for \"flatpak run\": %s",
error->message);
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
if (env == NULL)
{
if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
{
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_INVALID_ARGS,
"Could not load environment for \"flatpak run\": %s",
error->message);
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
g_clear_error (&error);
}
}
g_clear_error (&error);
g_warning ("Environment for \"flatpak run\" was not found, "
"falling back to current environment");
env = g_strdupv (original_environ);
}
}
if ((flatpak = g_getenv ("FLATPAK_PORTAL_MOCK_FLATPAK")) != NULL)
g_ptr_array_add (flatpak_argv, g_strdup (flatpak));