From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: pty: Fix a race issue in startup of pseudo console.
Date: Thu, 4 Mar 2021 17:56:34 +0900 [thread overview]
Message-ID: <20210304085634.1659-1-takashi.yano@nifty.ne.jp> (raw)
- If two non-cygwin apps are started simultaneously and this is the
first execution of non-cygwin apps in the pty, these occasionally
hang up. The cause is the race issue between term_has_pcon_cap(),
reset_switch_to_pcon() and setup_pseudoconsole(). This patch fixes
the issue.
---
winsup/cygwin/fhandler_tty.cc | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 3fcaa8277..930501d01 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1118,15 +1118,20 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
}
}
}
- if (get_ttyp ()->pcon_pid && get_ttyp ()->pcon_pid != myself->pid
- && !!pinfo (get_ttyp ()->pcon_pid))
- /* There is a process which is grabbing pseudo console. */
- return;
if (isHybrid)
return;
+ WaitForSingleObject (pcon_mutex, INFINITE);
+ if (get_ttyp ()->pcon_pid && get_ttyp ()->pcon_pid != myself->pid
+ && !!pinfo (get_ttyp ()->pcon_pid))
+ {
+ /* There is a process which is grabbing pseudo console. */
+ ReleaseMutex (pcon_mutex);
+ return;
+ }
get_ttyp ()->pcon_pid = 0;
get_ttyp ()->switch_to_pcon_in = false;
get_ttyp ()->pcon_activated = false;
+ ReleaseMutex (pcon_mutex);
}
ssize_t __stdcall
@@ -3538,6 +3543,7 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
goto maybe_dumb;
/* Check if terminal has CSI6n */
+ WaitForSingleObject (pcon_mutex, INFINITE);
WaitForSingleObject (input_mutex, INFINITE);
/* Set pcon_activated and pcon_start so that the response
will sent to io_handle rather than io_handle_cyg. */
@@ -3573,6 +3579,7 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
while (len);
get_ttyp ()->pcon_activated = false;
get_ttyp ()->pcon_pid = 0;
+ ReleaseMutex (pcon_mutex);
if (len == 0)
goto not_has_csi6n;
@@ -3588,6 +3595,7 @@ not_has_csi6n:
get_ttyp ()->pcon_start = false;
get_ttyp ()->pcon_activated = false;
ReleaseMutex (input_mutex);
+ ReleaseMutex (pcon_mutex);
maybe_dumb:
get_ttyp ()->pcon_cap_checked = true;
return false;
--
2.30.1
next reply other threads:[~2021-03-04 8:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-04 8:56 Takashi Yano [this message]
2021-03-05 15:12 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210304085634.1659-1-takashi.yano@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).