summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-05-21 13:45:03 +0100
committerAlexander Larsson <alexander.larsson@gmail.com>2021-05-25 11:11:03 +0200
commit526dae92418616c71517945e810227416f160ce6 (patch)
treee805757e732133d5fc54c0e82b5cd260d0db1843
parenta09d07f085d85efdf34934ecc864a6a5ce9af761 (diff)
downloadflatpak-526dae92418616c71517945e810227416f160ce6.tar.gz
portal: Remap --env-fd into child process's fd space
Just because we can allocate a new, unused fd in the portal's fd space, that doesn't mean that fd number is going to be unused in the child process's fd space: we might need to remap it. Resolves: flatpak/flatpak#4286 Fixes: aeb6a7ab "portal: Convert --env in extra-args into --env-fd" Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--portal/flatpak-portal.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/portal/flatpak-portal.c b/portal/flatpak-portal.c
index 2eb25c4d..f34835a5 100644
--- a/portal/flatpak-portal.c
+++ b/portal/flatpak-portal.c
@@ -1092,6 +1092,7 @@ handle_spawn (PortalFlatpak *object,
if (env_string->len > 0)
{
+ FdMapEntry fd_map_entry;
g_auto(GLnxTmpfile) env_tmpf = { 0, };
if (!flatpak_buffer_to_sealed_memfd_or_tmpfile (&env_tmpf, "environ",
@@ -1103,9 +1104,16 @@ handle_spawn (PortalFlatpak *object,
}
env_fd = glnx_steal_fd (&env_tmpf.fd);
- child_setup_data.env_fd = env_fd;
+
+ /* Use a fd that hasn't been used yet. We might have to reshuffle
+ * fd_map_entry.to, a bit later. */
+ fd_map_entry.from = env_fd;
+ fd_map_entry.to = ++max_fd;
+ fd_map_entry.final = fd_map_entry.to;
+ g_array_append_val (fd_map, fd_map_entry);
+
g_ptr_array_add (flatpak_argv,
- g_strdup_printf ("--env-fd=%d", env_fd));
+ g_strdup_printf ("--env-fd=%d", fd_map_entry.final));
}
for (i = 0; unset_env != NULL && unset_env[i] != NULL; i++)