msys2-runtime: backport another fix for hanging pipes

See #2471
This commit is contained in:
Christoph Reiter
2021-05-03 18:02:07 +02:00
parent 6522cb48c6
commit bd2ba45509
2 changed files with 73 additions and 4 deletions

View File

@@ -0,0 +1,66 @@
From 38cbabfa51fef46f53fc3b2f79091062fe15c196 Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Mon, 19 Apr 2021 19:30:45 +0900
Subject: [PATCH 33/N] Cygwin: console: Fix race issue regarding
cons_master_thread().
- With this patch, the race issue regarding starting/stopping
cons_master_thread() introduced by commit ff4440fc is fixed.
Addresses:
https://cygwin.com/pipermail/cygwin/2021-April/248292.html
---
winsup/cygwin/fhandler_console.cc | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 0b33a13..e418aac 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -48,6 +48,7 @@ details. */
#define con_is_legacy (shared_console_info && con.is_legacy)
#define CONS_THREAD_SYNC "cygcons.thread_sync"
+static bool NO_COPY master_thread_started = false;
const unsigned fhandler_console::MAX_WRITE_CHARS = 16384;
@@ -184,6 +185,7 @@ cons_master_thread (VOID *arg)
GetCurrentProcess (), &thread_sync_event,
0, FALSE, DUPLICATE_SAME_ACCESS);
SetEvent (thread_sync_event);
+ master_thread_started = true;
/* Do not touch class members after here because the class instance
may have been destroyed. */
fhandler_console::cons_master_thread (&handle_set, ttyp);
@@ -370,6 +372,8 @@ fhandler_console::set_unit ()
}
if (!created && shared_console_info)
{
+ while (con.owner > MAX_PID)
+ Sleep (1);
pinfo p (con.owner);
if (!p)
con.owner = myself->pid;
@@ -1393,14 +1397,16 @@ fhandler_console::close ()
release_output_mutex ();
- if (shared_console_info && con.owner == myself->pid)
+ if (shared_console_info && con.owner == myself->pid
+ && master_thread_started)
{
char name[MAX_PATH];
shared_name (name, CONS_THREAD_SYNC, get_minor ());
thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name);
- con.owner = 0;
+ con.owner = MAX_PID + 1;
WaitForSingleObject (thread_sync_event, INFINITE);
CloseHandle (thread_sync_event);
+ con.owner = 0;
}
CloseHandle (input_mutex);
--
2.31.1

View File

@@ -4,7 +4,7 @@
pkgbase=msys2-runtime
pkgname=('msys2-runtime' 'msys2-runtime-devel')
pkgver=3.2.0
pkgrel=4
pkgrel=5
pkgdesc="Cygwin POSIX emulation engine"
arch=('i686' 'x86_64')
url="https://www.cygwin.com/"
@@ -54,7 +54,8 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$
0029-Do-not-show-Error-dialogs-by-default.patch
0030-uname-limit-sysname-to-MSYS-or-MINGW.patch
0031-CI-give-the-cygwin-sync-job-explicit-write-permissio.patch
0032-Cygwin-path_conv-Try-to-handle-native-symlinks-more-.patch)
0032-Cygwin-path_conv-Try-to-handle-native-symlinks-more-.patch
0033-Cygwin-console-Fix-race-issue-regarding-cons_master_.patch)
sha256sums=('SKIP'
'605f3f31dcca983fad2659f2d8f3531217e3f133757b40b0977e6a17c406c147'
'5d120d24ce55ef08bf459781610e32c4a8e5e0eac73971a60e80590c6432d940'
@@ -87,7 +88,8 @@ sha256sums=('SKIP'
'969ace2675ebec747d0ccfe2540210ebac9974973b8b93325aecb53351514b76'
'301422428472f693ad3a659b1279c969d5457eaab77be4dc0a389b2f5c5b6a55'
'acbf8e7fea8089d474a63d8e12fd68e13f33967911eb785895183619c4307092'
'ab78d325691fa6af631a73c3292537263b58a53eb0ab35c65d431a8536e8e12c')
'ab78d325691fa6af631a73c3292537263b58a53eb0ab35c65d431a8536e8e12c'
'679c11a3c6f96aa99c7d6bf6529d7cd22fbb23b24a06196ab06a9dfec82355fe')
# Helper macros to help make tasks easier #
apply_patch_with_msg() {
@@ -156,7 +158,8 @@ prepare() {
0029-Do-not-show-Error-dialogs-by-default.patch \
0030-uname-limit-sysname-to-MSYS-or-MINGW.patch \
0031-CI-give-the-cygwin-sync-job-explicit-write-permissio.patch \
0032-Cygwin-path_conv-Try-to-handle-native-symlinks-more-.patch
0032-Cygwin-path_conv-Try-to-handle-native-symlinks-more-.patch \
0033-Cygwin-console-Fix-race-issue-regarding-cons_master_.patch
}
build() {