* [PATCH] Cygwin: pty: Revise code to make system_printf() work after close.
@ 2020-05-21 8:25 Takashi Yano
2020-05-21 18:50 ` Ken Brown
2020-05-25 9:00 ` Corinna Vinschen
0 siblings, 2 replies; 3+ messages in thread
From: Takashi Yano @ 2020-05-21 8:25 UTC (permalink / raw)
To: cygwin-patches
- After commit 0365031ce1347600d854a23f30f1355745a1765c, the issue
https://cygwin.com/pipermail/cygwin-patches/2020q2/010259.html
occurs. This patch fixes the issue.
---
winsup/cygwin/fhandler_tty.cc | 15 ++++++++++++---
winsup/cygwin/tty.cc | 23 +++++++++++++++++++++++
winsup/cygwin/tty.h | 2 ++
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 02b78cd2c..5faf896e4 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -64,6 +64,7 @@ static int pcon_attached_to = -1;
static bool isHybrid;
static bool do_not_reset_switch_to_pcon;
static bool freeconsole_on_close = true;
+static tty *last_ttyp = NULL;
void
clear_pcon_attached_to (void)
@@ -89,7 +90,11 @@ set_switch_to_pcon (void)
ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
SetConsoleMode (ptys->get_handle (), mode);
}
+ return;
}
+ /* No pty slave opened */
+ if (last_ttyp) /* Make system_printf() work after closing pty slave */
+ last_ttyp->set_switch_to_pcon_out (true);
}
static void
@@ -741,7 +746,10 @@ fhandler_pty_slave::~fhandler_pty_slave ()
needed to make GNU screen and tmux work in Windows 10
1903. */
if (attached == 0)
- pcon_attached_to = -1;
+ {
+ pcon_attached_to = -1;
+ last_ttyp = get_ttyp ();
+ }
if (used == 0)
{
init_console_handler (false);
@@ -948,6 +956,7 @@ fhandler_pty_slave::open (int flags, mode_t)
init_console_handler (true);
}
+ isHybrid = false;
get_ttyp ()->pcon_pid = 0;
get_ttyp ()->switch_to_pcon_in = false;
get_ttyp ()->switch_to_pcon_out = false;
@@ -1012,7 +1021,6 @@ fhandler_pty_slave::close ()
termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex);
if (pcon_attached_to == get_minor ())
get_ttyp ()->num_pcon_attached_slaves --;
- set_switch_to_pcon (2); /* Make system_printf() work after close. */
return 0;
}
@@ -2888,7 +2896,8 @@ fhandler_pty_slave::wait_pcon_fwd (void)
get_ttyp ()->pcon_last_time = GetTickCount ();
ResetEvent (get_ttyp ()->fwd_done);
release_output_mutex ();
- cygwait (get_ttyp ()->fwd_done, INFINITE);
+ while (get_ttyp ()->fwd_done
+ && cygwait (get_ttyp ()->fwd_done, 1) == WAIT_TIMEOUT);
}
void
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 0663dc5ee..3fc46fb29 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -294,3 +294,26 @@ tty_min::ttyname ()
d.parse (ntty);
return d.name ();
}
+
+void
+tty::set_switch_to_pcon_out (bool v)
+{
+ if (switch_to_pcon_out != v)
+ {
+ wait_pcon_fwd ();
+ switch_to_pcon_out = v;
+ }
+}
+
+void
+tty::wait_pcon_fwd (void)
+{
+ const int sleep_in_pcon = 16;
+ const int time_to_wait = sleep_in_pcon * 2 + 1/* margine */;
+ pcon_last_time = GetTickCount ();
+ while (GetTickCount () - pcon_last_time < time_to_wait)
+ {
+ int tw = time_to_wait - (GetTickCount () - pcon_last_time);
+ cygwait (tw);
+ }
+}
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index a24afad06..c4dd2e458 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -140,6 +140,8 @@ public:
void set_master_ctl_closed () {master_pid = -1;}
static void __stdcall create_master (int);
static void __stdcall init_session ();
+ void set_switch_to_pcon_out (bool v);
+ void wait_pcon_fwd (void);
friend class fhandler_pty_common;
friend class fhandler_pty_master;
friend class fhandler_pty_slave;
--
2.21.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Cygwin: pty: Revise code to make system_printf() work after close.
2020-05-21 8:25 [PATCH] Cygwin: pty: Revise code to make system_printf() work after close Takashi Yano
@ 2020-05-21 18:50 ` Ken Brown
2020-05-25 9:00 ` Corinna Vinschen
1 sibling, 0 replies; 3+ messages in thread
From: Ken Brown @ 2020-05-21 18:50 UTC (permalink / raw)
To: cygwin-patches
On 5/21/2020 4:25 AM, Takashi Yano via Cygwin-patches wrote:
> - After commit 0365031ce1347600d854a23f30f1355745a1765c, the issue
> https://cygwin.com/pipermail/cygwin-patches/2020q2/010259.html
> occurs. This patch fixes the issue.
Thanks. I can confirm that it's fixed.
Ken
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Cygwin: pty: Revise code to make system_printf() work after close.
2020-05-21 8:25 [PATCH] Cygwin: pty: Revise code to make system_printf() work after close Takashi Yano
2020-05-21 18:50 ` Ken Brown
@ 2020-05-25 9:00 ` Corinna Vinschen
1 sibling, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2020-05-25 9:00 UTC (permalink / raw)
To: cygwin-patches
On May 21 17:25, Takashi Yano via Cygwin-patches wrote:
> - After commit 0365031ce1347600d854a23f30f1355745a1765c, the issue
> https://cygwin.com/pipermail/cygwin-patches/2020q2/010259.html
> occurs. This patch fixes the issue.
> ---
> winsup/cygwin/fhandler_tty.cc | 15 ++++++++++++---
> winsup/cygwin/tty.cc | 23 +++++++++++++++++++++++
> winsup/cygwin/tty.h | 2 ++
> 3 files changed, 37 insertions(+), 3 deletions(-)
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-25 9:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21 8:25 [PATCH] Cygwin: pty: Revise code to make system_printf() work after close Takashi Yano
2020-05-21 18:50 ` Ken Brown
2020-05-25 9:00 ` Corinna Vinschen
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).