From 7fac9ccbf78a3490e507559ef6969f68e71bc5ea Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Thu, 15 Feb 2024 13:26:18 +0000 Subject: [PATCH] pv-wrap: Use g_fdwalk_set_cloexec() instead of flatpak_close_fds_workaround() This is essentially a backport of the change proposed in <https://github.com/flatpak/flatpak/pull/5687>. Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/flatpak-bwrap.c | 6 ++++++ pressure-vessel/flatpak-utils-base.c | 2 ++ pressure-vessel/wrap-setup.c | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pressure-vessel/flatpak-bwrap.c b/pressure-vessel/flatpak-bwrap.c index 932728761..59e6710d5 100644 --- a/pressure-vessel/flatpak-bwrap.c +++ b/pressure-vessel/flatpak-bwrap.c @@ -507,7 +507,13 @@ flatpak_bwrap_child_setup (GArray *fd_array, int i; if (close_fd_workaround) +#if 0 flatpak_close_fds_workaround (3); +#else + /* pressure-vessel-specific change for now, but see + * https://github.com/flatpak/flatpak/pull/5687 */ + g_fdwalk_set_cloexec (3); +#endif /* If no fd_array was specified, don't care. */ if (fd_array == NULL) diff --git a/pressure-vessel/flatpak-utils-base.c b/pressure-vessel/flatpak-utils-base.c index 92872352b..d654f988e 100644 --- a/pressure-vessel/flatpak-utils-base.c +++ b/pressure-vessel/flatpak-utils-base.c @@ -120,6 +120,7 @@ flatpak_canonicalize_filename (const char *path) return g_file_get_path (file); } +#if 0 /* There is a dead-lock in glib versions before 2.60 when it closes * the fds. See: https://gitlab.gnome.org/GNOME/glib/merge_requests/490 * This was hitting the test-suite a lot, so we work around it by using @@ -135,3 +136,4 @@ flatpak_close_fds_workaround (int start_fd) for (fd = start_fd; fd < max_open_fds; fd++) fcntl (fd, F_SETFD, FD_CLOEXEC); } +#endif diff --git a/pressure-vessel/wrap-setup.c b/pressure-vessel/wrap-setup.c index cc7b20bd1..7f7b897cf 100644 --- a/pressure-vessel/wrap-setup.c +++ b/pressure-vessel/wrap-setup.c @@ -98,8 +98,8 @@ test_bwrap_executable (const char *bwrap_executable, g_ptr_array_add (argv, (char *) "true"); g_ptr_array_add (argv, NULL); - /* We use LEAVE_DESCRIPTORS_OPEN to work around a deadlock in older GLib, - * see flatpak_close_fds_workaround */ + /* We use LEAVE_DESCRIPTORS_OPEN and set CLOEXEC in the child_setup, + * to work around a deadlock in GLib < 2.60 */ if (!g_spawn_sync (NULL, /* cwd */ (gchar **) argv->pdata, NULL, /* environ */ -- GitLab