glib: backport fix for gspawn regression

Fixes #11159
This commit is contained in:
Christoph Reiter
2022-04-05 21:15:11 +02:00
parent 1b46cb0511
commit b72012b65d
2 changed files with 89 additions and 1 deletions

View File

@@ -0,0 +1,83 @@
From 44a82bf84cf77f87b70a5108372b7d869bac8aa1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
Date: Mon, 4 Apr 2022 15:46:23 +0400
Subject: [PATCH] glib/win32: fix spawn from GUI regression
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In commit 674072b13 ("glib/win32: check if dup() failed in helper
process"), I happily added checks for dup() calls in the spawn helper.
However, I didn't realize that GUI applications do not necessarily have
a console attached, and will now fail spawning processes.
One way to check that is via a _fileno() call, as explained in:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fileno?view=msvc-170#return-value
Fixes:
https://gitlab.gnome.org/GNOME/glib/-/issues/2628
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
glib/gspawn-win32-helper.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/glib/gspawn-win32-helper.c b/glib/gspawn-win32-helper.c
index 2ca9009a4c..4729ee46ec 100644
--- a/glib/gspawn-win32-helper.c
+++ b/glib/gspawn-win32-helper.c
@@ -292,9 +292,13 @@ main (int ignored_argc, char **ignored_argv)
checked_dup2 (fd, 1, child_err_report_fd);
}
- saved_stderr_fd = reopen_noninherited (dup (2), _O_WRONLY);
- if (saved_stderr_fd == -1)
- write_err_and_exit (child_err_report_fd, CHILD_DUP_FAILED);
+ /* GUI application do not necessarily have a stderr */
+ if (_fileno (stderr) == 2)
+ {
+ saved_stderr_fd = reopen_noninherited (dup (2), _O_WRONLY);
+ if (saved_stderr_fd == -1)
+ write_err_and_exit (child_err_report_fd, CHILD_DUP_FAILED);
+ }
maxfd = MAX (saved_stderr_fd, maxfd);
if (argv[ARG_STDERR][0] == '-')
@@ -354,8 +358,11 @@ main (int ignored_argc, char **ignored_argv)
child_err_report_fd = checked_dup2 (child_err_report_fd, maxfd, child_err_report_fd);
maxfd++;
helper_sync_fd = checked_dup2 (helper_sync_fd, maxfd, child_err_report_fd);
- maxfd++;
- saved_stderr_fd = checked_dup2 (saved_stderr_fd, maxfd, child_err_report_fd);
+ if (saved_stderr_fd >= 0)
+ {
+ maxfd++;
+ saved_stderr_fd = checked_dup2 (saved_stderr_fd, maxfd, child_err_report_fd);
+ }
{
GHashTableIter iter;
@@ -381,7 +388,8 @@ main (int ignored_argc, char **ignored_argv)
g_hash_table_add (fds, GINT_TO_POINTER (child_err_report_fd));
g_hash_table_add (fds, GINT_TO_POINTER (helper_sync_fd));
- g_hash_table_add (fds, GINT_TO_POINTER (saved_stderr_fd));
+ if (saved_stderr_fd >= 0)
+ g_hash_table_add (fds, GINT_TO_POINTER (saved_stderr_fd));
/* argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3
* upwards should be closed
@@ -430,7 +438,9 @@ main (int ignored_argc, char **ignored_argv)
* Remove redirection so that they would go to original stderr
* instead of being treated as part of stderr of child process.
*/
- dup2 (saved_stderr_fd, 2);
+ if (saved_stderr_fd >= 0)
+ dup2 (saved_stderr_fd, 2);
+
if (handle == -1 && saved_errno != 0)
{
int ec = (saved_errno == ENOENT)
--
GitLab

View File

@@ -7,7 +7,7 @@ _realname=glib2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.72.0
pkgrel=1
pkgrel=2
url="https://gitlab.gnome.org/GNOME/glib"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
@@ -28,12 +28,14 @@ options=('strip' '!debug' 'staticlibs')
source=("https://download.gnome.org/sources/glib/${pkgver%.*}/glib-${pkgver}.tar.xz"
0001-Update-g_fopen-g_open-and-g_creat-to-open-with-FILE_.patch
0002-disable_glib_compile_schemas_warning.patch
0003-gspawn-backport.patch
glib-compile-schemas.hook.in
gio-querymodules.hook.in
pyscript2exe.py)
sha256sums=('d7bef0d4c4e7a62e08efb8e5f252a01357007b9588a87ff2b463a3857011f79d'
'51d02360a1ee978fd45e77b84bca9cfbcf080d91986b5c0efe0732779c6a54ec'
'396c25cfd740ffbb72209133c7b9453173167577265a4bb14502678de8d5a8f9'
'099b2ff7c42694d1ededa11c70f639da7fce9264a92e7f03eab7da0b40d365ee'
'0c3d54636407e0e13429b73959cace626253cd772e1d4870de0fb92b0b99545a'
'f18d27d98709dba8c5f9756672baaf0158fb4353c9edbdc2e80021f88ff34ced'
'e57174517b08cf8f9fb4f43a381d342d23d2db3cad661107f35ca21c39b5734d')
@@ -52,6 +54,9 @@ prepare() {
apply_patch_with_msg 0001-Update-g_fopen-g_open-and-g_creat-to-open-with-FILE_.patch
apply_patch_with_msg 0002-disable_glib_compile_schemas_warning.patch
# https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2588
apply_patch_with_msg 0003-gspawn-backport.patch
}
build() {