Skip to content

Commit 2fa5104

Browse files
committed
Cygwin: pty: Make pcon_start handling more multi thread durable
Currently, if the CSI6n response is divided into "CSI10;2" and "R", and another thread call master write() with "c", the data written to nat pipe will be interleaved like "CSI10;2cR". The first "CSI10;2" make the 'state' 1, and in state == 1, all the data written goes to 'wpbuf[]'. This may break startup of pseudo console. With this patch, the thread ID of the thread that write the first ESC char to 'wpbuf[]' is stored in 'wp_tid', and only if the thread ID matches 'wp_tid' will be written to 'wpbuf[]'. Fixes: bb42852 ("Cygwin: pty: Implement new pseudo console support.") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Reviewed-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent c8bbec4 commit 2fa5104

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

winsup/cygwin/fhandler/pty.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22082208
static char wpbuf[wpbuf_len];
22092209
static int ixput = 0;
22102210
static int state = 0;
2211+
static DWORD wp_tid = 0;
22112212

22122213
DWORD n;
22132214
WaitForSingleObject (input_mutex, mutex_timeout);
@@ -2220,8 +2221,9 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22202221
line_edit (wpbuf, ixput, ti, &ret);
22212222
ixput = 0;
22222223
state = 1;
2224+
wp_tid = _my_tls.thread_id;
22232225
}
2224-
if (state == 1)
2226+
if (state == 1 && wp_tid == _my_tls.thread_id)
22252227
{
22262228
if (ixput < wpbuf_len)
22272229
wpbuf[ixput++] = p[i];
@@ -2237,7 +2239,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22372239
line_edit (p + i, 1, ti, &ret);
22382240
len = orig_len - i - 1;
22392241
ptr = p + i + 1;
2240-
if (state == 1 && p[i] == 'R')
2242+
if (state == 1 && wp_tid == _my_tls.thread_id && p[i] == 'R')
22412243
state = 2;
22422244
if (state == 2)
22432245
{
@@ -2248,6 +2250,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22482250
WriteFile (to_slave_nat, wpbuf, ixput, &n, NULL);
22492251
ixput = 0;
22502252
state = 0;
2253+
wp_tid = 0;
22512254
get_ttyp ()->req_xfer_input = false;
22522255
get_ttyp ()->pcon_start = false;
22532256
break;

0 commit comments

Comments
 (0)