From e75520c3d89e3bedd211a98db0df5e6d31738449 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 23 May 2026 21:28:16 +0200 Subject: [PATCH] msys2-runtime: fix deadlock in pcon teardown See https://github.com/msys2/msys2-runtime/pull/339 also includes some fixes for new build issues, see: https://github.com/msys2/msys2-runtime/pull/340 --- ...an-unused-variable-causing-a-build-e.patch | 32 +++++++++++++ ...onsole-fix-deadlock-in-pcon-teardown.patch | 47 +++++++++++++++++++ msys2-runtime/PKGBUILD | 17 +++++-- msys2-runtime/msys2-runtime.commit | 2 +- 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 msys2-runtime/0040-cygcheck-remove-an-unused-variable-causing-a-build-e.patch create mode 100644 msys2-runtime/0041-Cygwin-console-fix-deadlock-in-pcon-teardown.patch diff --git a/msys2-runtime/0040-cygcheck-remove-an-unused-variable-causing-a-build-e.patch b/msys2-runtime/0040-cygcheck-remove-an-unused-variable-causing-a-build-e.patch new file mode 100644 index 00000000000..3a7b124f534 --- /dev/null +++ b/msys2-runtime/0040-cygcheck-remove-an-unused-variable-causing-a-build-e.patch @@ -0,0 +1,32 @@ +From fc2528ff085548ef73b6960290184e1d1724f257 Mon Sep 17 00:00:00 2001 +From: Christoph Reiter +Date: Mon, 18 May 2026 21:13:38 +0200 +Subject: [PATCH 40/N] cygcheck: remove an unused variable causing a build + error with GCC 16 + +Since gcc 16 this triggers -Werror=unused-but-set-variable= +Remove the unused variable. +--- + winsup/utils/mingw/cygcheck.cc | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/winsup/utils/mingw/cygcheck.cc b/winsup/utils/mingw/cygcheck.cc +index 1637683..22c7d18 100644 +--- a/winsup/utils/mingw/cygcheck.cc ++++ b/winsup/utils/mingw/cygcheck.cc +@@ -1706,7 +1706,6 @@ dump_sysinfo () + else + { + char sep = strchr (s, ';') ? ';' : ':'; +- int count_path_items = 0; + while (1) + { + for (e = s; *e && *e != sep; e++); +@@ -1714,7 +1713,6 @@ dump_sysinfo () + printf ("\t%.*s\n", (int) (e - s), s); + else + puts ("\t."); +- count_path_items++; + if (!*e) + break; + s = e + 1; diff --git a/msys2-runtime/0041-Cygwin-console-fix-deadlock-in-pcon-teardown.patch b/msys2-runtime/0041-Cygwin-console-fix-deadlock-in-pcon-teardown.patch new file mode 100644 index 00000000000..780e7cd912c --- /dev/null +++ b/msys2-runtime/0041-Cygwin-console-fix-deadlock-in-pcon-teardown.patch @@ -0,0 +1,47 @@ +From 01d6c708f9221334d18ab332621b6d87eb12d37e Mon Sep 17 00:00:00 2001 +From: Christoph Reiter +Date: Mon, 18 May 2026 19:52:49 +0100 +Subject: [PATCH 41/N] Cygwin: console: fix deadlock in pcon teardown + +When a process inside a pseudo console (pcon) exits, the sequence was: + + exit() + -> atexit handlers (including pcon_hand_over_proc) + pcon_hand_over_proc closes parent_pty_input_mutex + -- handle slot now free to be recycled -- + -> _exit() -> do_exit() -> close_all_files() -> fhandler_console::close() + set_input_mode() waits on input_mutex <-- hangs + +The fix, suggested by Takashi Yano: remove the atexit registration +entirely and instead call pcon_hand_over_proc() directly from +fhandler_console::close(), after both input_mutex and output_mutex +have been closed. By that point close() has already waited for +cons_master_thread to exit, so parent_pty_input_mutex is no longer +accessed by any other thread and can be safely closed. + +Fixes: https://github.com/msys2/msys2-runtime/issues/338 +--- + winsup/cygwin/fhandler/console.cc | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc +index 6220a91..224177b 100644 +--- a/winsup/cygwin/fhandler/console.cc ++++ b/winsup/cygwin/fhandler/console.cc +@@ -1954,7 +1954,6 @@ fhandler_console::setup_pcon_hand_over () + if (get_console_process_id (owner, true, false, false, false)) + { + inside_pcon = true; +- atexit (fhandler_console::pcon_hand_over_proc); + parent_pty = i; + parent_pty_input_mutex = + cygwin_shared->tty[i]->open_input_mutex (MAXIMUM_ALLOWED); +@@ -2092,6 +2091,8 @@ fhandler_console::close (int flag) + CloseHandle (output_mutex); + output_mutex = NULL; + ++ pcon_hand_over_proc (); ++ + WaitForSingleObject (shared_info_mutex, INFINITE); + if (--shared_info_state[unit] == 0 && shared_console_info[unit]) + { diff --git a/msys2-runtime/PKGBUILD b/msys2-runtime/PKGBUILD index e6d692d8643..eba0e221aa2 100644 --- a/msys2-runtime/PKGBUILD +++ b/msys2-runtime/PKGBUILD @@ -4,7 +4,7 @@ pkgbase=msys2-runtime pkgname=('msys2-runtime' 'msys2-runtime-devel') pkgver=3.6.9 -pkgrel=1 +pkgrel=2 pkgdesc="Cygwin POSIX emulation engine" arch=('x86_64') url="https://www.cygwin.com/" @@ -21,6 +21,7 @@ makedepends=('cocom' 'mingw-w64-cross-gcc' 'mingw-w64-cross-zlib' 'zlib-devel' + 'libzstd-devel' 'gettext-devel' 'libiconv-devel' 'autotools' @@ -68,9 +69,11 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$ 0036-Avoid-sharing-cygheaps-across-Cygwin-versions.patch 0037-uname-report-msys2-runtime-commit-hash-too.patch 0038-Cygwin-Adjust-CWD-magic-to-accommodate-for-the-lates.patch - 0039-Cygwin-Fix-segfault-when-XSAVE-area-sizes-are-unalig.patch) + 0039-Cygwin-Fix-segfault-when-XSAVE-area-sizes-are-unalig.patch + 0040-cygcheck-remove-an-unused-variable-causing-a-build-e.patch + 0041-Cygwin-console-fix-deadlock-in-pcon-teardown.patch) sha256sums=('f05acd30000aa003b1bb040cdf24ac4c85e85d0bc924126e5cafc66de975342d' - '5f9262953542e823f7b5535257936dab5209d472aabd379b14584fe45c5311c8' + '73f62e3cb77d300137766a9e0b6e7f819c574b54ea11555f843ef0bdc63f20fd' 'eae9773ed4d226f1938aceb4e0f25047ff3844758677a2c0f8a8b98bd7701015' 'ed02e5bd61ac289e8c28c921bd71c7fa1a84f551a7f148ef622c51e06a49de51' '0ee828e4e50cbe51d3fbdfa79d84224c3a78b1fff09bac8daf3cd6ee7ee2c75a' @@ -109,7 +112,9 @@ sha256sums=('f05acd30000aa003b1bb040cdf24ac4c85e85d0bc924126e5cafc66de975342d' '69803c6c6dc6939ec27c71dc3fc21fc9d71cb6475f5a0c395f73a8027b733fe6' '9d991051bf5ce05fc882fb8bfc5b6c2239e7eb0cbe71b1db61c52599b581da9c' '9256c38f9d41e37b31d080df14f1d49633caa1e5a17a3e7234d5c2ac67e191a7' - '8f7fa3b5b61921be8ea51b6b7d158e1d024c2e70261db9078ae0c207471143c2') + '8f7fa3b5b61921be8ea51b6b7d158e1d024c2e70261db9078ae0c207471143c2' + 'c3fef6664cc59a7113d19026438c0fda20607f1f58e805ba17a6b3d7e1a113d4' + 'd4bc91890d7a0075350f9af083298aef2d288fa6a96dda03fd9df062a72c5713') # Helper macros to help make tasks easier # apply_patch_with_msg() { @@ -186,7 +191,9 @@ prepare() { 0036-Avoid-sharing-cygheaps-across-Cygwin-versions.patch \ 0037-uname-report-msys2-runtime-commit-hash-too.patch \ 0038-Cygwin-Adjust-CWD-magic-to-accommodate-for-the-lates.patch \ - 0039-Cygwin-Fix-segfault-when-XSAVE-area-sizes-are-unalig.patch + 0039-Cygwin-Fix-segfault-when-XSAVE-area-sizes-are-unalig.patch \ + 0040-cygcheck-remove-an-unused-variable-causing-a-build-e.patch \ + 0041-Cygwin-console-fix-deadlock-in-pcon-teardown.patch } build() { diff --git a/msys2-runtime/msys2-runtime.commit b/msys2-runtime/msys2-runtime.commit index 61292ce885b..84f24a143b3 100644 --- a/msys2-runtime/msys2-runtime.commit +++ b/msys2-runtime/msys2-runtime.commit @@ -1 +1 @@ -aa532e7bbf59a3ec1e29e13c9e8515d545cb2e16 +01d6c708f9221334d18ab332621b6d87eb12d37e