From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66136 invoked by alias); 22 Jan 2020 10:06:06 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 66094 invoked by uid 9078); 22 Jan 2020 10:06:06 -0000 Date: Wed, 22 Jan 2020 10:06:00 -0000 Message-ID: <20200122100606.66092.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Fix reopening slave in push_to_pcon_screenbuffer(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 4e78f8ea163fec468072e8fe1f498b9abaaf838f X-Git-Newrev: da4ee7d60b9ff0bcdc081609a4467adb428d58e6 X-SW-Source: 2020-q1/txt/msg00022.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=da4ee7d60b9ff0bcdc081609a4467adb428d58e6 commit da4ee7d60b9ff0bcdc081609a4467adb428d58e6 Author: Takashi Yano Date: Tue Jan 21 23:41:44 2020 +0900 Cygwin: pty: Fix reopening slave in push_to_pcon_screenbuffer(). - For programs compiled with -mwindows option, reopening slave is needed in push_to_pcon_screenbuffer(), however, it was not at appropriate place. This causes the problem reported in https://www.cygwin.com/ml/cygwin/2020-01/msg00161.html. This patch fixes the issue. Diff: --- winsup/cygwin/fhandler_tty.cc | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 8ed1f8a..50f0378 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1273,9 +1273,21 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len) break; } + int retry_count; + retry_count = 0; DWORD dwMode, flags; flags = ENABLE_VIRTUAL_TERMINAL_PROCESSING; - GetConsoleMode (get_output_handle (), &dwMode); + while (!GetConsoleMode (get_output_handle (), &dwMode)) + { + termios_printf ("GetConsoleMode failed, %E"); + /* Re-open handles */ + this->close (); + this->open (0, 0); + /* Fix pseudo console window size */ + this->ioctl (TIOCSWINSZ, &get_ttyp ()->winsize); + if (++retry_count > 3) + goto cleanup; + } if (!(get_ttyp ()->ti.c_oflag & OPOST) || !(get_ttyp ()->ti.c_oflag & ONLCR)) flags |= DISABLE_NEWLINE_AUTO_RETURN; @@ -1284,8 +1296,6 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len) p = buf; DWORD wLen, written; written = 0; - int retry_count; - retry_count = 0; BOOL (WINAPI *WriteFunc) (HANDLE, LPCVOID, DWORD, LPDWORD, LPOVERLAPPED); WriteFunc = WriteFile_Orig ? WriteFile_Orig : WriteFile; @@ -1294,16 +1304,13 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len) if (!WriteFunc (get_output_handle (), p, nlen - written, &wLen, NULL)) { termios_printf ("WriteFile failed, %E"); - this->open (0, 0); /* Re-open handles */ - /* Fix pseudo console window size */ - struct winsize win; - this->ioctl (TIOCGWINSZ, &win); - this->ioctl (TIOCSWINSZ, &win); - if (++retry_count > 3) - break; + break; + } + else + { + written += wLen; + p += wLen; } - written += wLen; - p += wLen; } /* Detach from pseudo console and resume. */ flags = ENABLE_VIRTUAL_TERMINAL_PROCESSING;