Skip to content

Commit a8a61d8

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> (cherry picked from commit 2fa5104)
1 parent 25a9e4d commit a8a61d8

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
@@ -2191,6 +2191,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
21912191
static char wpbuf[wpbuf_len];
21922192
static int ixput = 0;
21932193
static int state = 0;
2194+
static DWORD wp_tid = 0;
21942195

21952196
DWORD n;
21962197
WaitForSingleObject (input_mutex, mutex_timeout);
@@ -2203,8 +2204,9 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22032204
line_edit (wpbuf, ixput, ti, &ret);
22042205
ixput = 0;
22052206
state = 1;
2207+
wp_tid = _my_tls.thread_id;
22062208
}
2207-
if (state == 1)
2209+
if (state == 1 && wp_tid == _my_tls.thread_id)
22082210
{
22092211
if (ixput < wpbuf_len)
22102212
wpbuf[ixput++] = p[i];
@@ -2220,7 +2222,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22202222
line_edit (p + i, 1, ti, &ret);
22212223
len = orig_len - i - 1;
22222224
ptr = p + i + 1;
2223-
if (state == 1 && p[i] == 'R')
2225+
if (state == 1 && wp_tid == _my_tls.thread_id && p[i] == 'R')
22242226
state = 2;
22252227
if (state == 2)
22262228
{
@@ -2231,6 +2233,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
22312233
WriteFile (to_slave_nat, wpbuf, ixput, &n, NULL);
22322234
ixput = 0;
22332235
state = 0;
2236+
wp_tid = 0;
22342237
get_ttyp ()->req_xfer_input = false;
22352238
get_ttyp ()->pcon_start = false;
22362239
break;

0 commit comments

Comments
 (0)