public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: pty: Call FreeConsole() only if attached to current pty.
@ 2020-05-17  2:34 Takashi Yano
  2020-05-19 10:04 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2020-05-17  2:34 UTC (permalink / raw)
  To: cygwin-patches

- After commit 071b8e0cbd4be33449c12bb0d58f514ed8ef893c, the problem
  reported in https://cygwin.com/pipermail/cygwin/2020-May/244873.html
  occurs. This is due to freeing console device accidentally rather
  than pseudo console. This patch makes sure to call FreeConsole()
  only if the process is attached to the pseudo console of the current
  pty.
---
 winsup/cygwin/fhandler_tty.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 8547ec7c4..467784255 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -708,7 +708,7 @@ fhandler_pty_slave::~fhandler_pty_slave ()
   if (!get_ttyp ())
     {
       /* Why comes here? Who clears _tc? */
-      if (freeconsole_on_close)
+      if (freeconsole_on_close && get_minor () == pcon_attached_to)
 	{
 	  FreeConsole ();
 	  pcon_attached_to = -1;
@@ -739,7 +739,7 @@ fhandler_pty_slave::~fhandler_pty_slave ()
       if (used == 0)
 	{
 	  init_console_handler (false);
-	  if (freeconsole_on_close)
+	  if (freeconsole_on_close && get_minor () == pcon_attached_to)
 	    {
 	      FreeConsole ();
 	      pcon_attached_to = -1;
@@ -3006,7 +3006,7 @@ fhandler_pty_slave::fixup_after_exec ()
       if (used == 1 /* About to close this tty */)
 	{
 	  init_console_handler (false);
-	  if (freeconsole_on_close)
+	  if (freeconsole_on_close && get_minor () == pcon_attached_to)
 	    {
 	      FreeConsole ();
 	      pcon_attached_to = -1;
-- 
2.21.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: pty: Call FreeConsole() only if attached to current pty.
  2020-05-17  2:34 [PATCH] Cygwin: pty: Call FreeConsole() only if attached to current pty Takashi Yano
@ 2020-05-19 10:04 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-05-19 10:04 UTC (permalink / raw)
  To: cygwin-patches

On May 17 11:34, Takashi Yano via Cygwin-patches wrote:
> - After commit 071b8e0cbd4be33449c12bb0d58f514ed8ef893c, the problem
>   reported in https://cygwin.com/pipermail/cygwin/2020-May/244873.html
>   occurs. This is due to freeing console device accidentally rather
>   than pseudo console. This patch makes sure to call FreeConsole()
>   only if the process is attached to the pseudo console of the current
>   pty.
> ---
>  winsup/cygwin/fhandler_tty.cc | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index 8547ec7c4..467784255 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -708,7 +708,7 @@ fhandler_pty_slave::~fhandler_pty_slave ()
>    if (!get_ttyp ())
>      {
>        /* Why comes here? Who clears _tc? */
> -      if (freeconsole_on_close)
> +      if (freeconsole_on_close && get_minor () == pcon_attached_to)
>  	{
>  	  FreeConsole ();
>  	  pcon_attached_to = -1;

Given it's used three times, wouldn't it make sense to put the entire
"if" construct into a fhandler_pty_slave inline method?


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-19 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-17  2:34 [PATCH] Cygwin: pty: Call FreeConsole() only if attached to current pty Takashi Yano
2020-05-19 10:04 ` 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).