public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: pty: Fix the issue regarding open and close multiple PTYs.
Date: Tue, 14 Jan 2020 16:30:00 -0000	[thread overview]
Message-ID: <20200114163040.127507.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bb7741acf800819a27c4edacddd231c6748fa1c9

commit bb7741acf800819a27c4edacddd231c6748fa1c9
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Tue Jan 14 13:10:54 2020 +0900

    Cygwin: pty: Fix the issue regarding open and close multiple PTYs.
    
    - If two PTYs are opened in the same process and the first one
      is closed, the helper process for the first PTY remains running.
      This patch fixes the issue.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 0837b63..84900fe 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2224,8 +2224,7 @@ fhandler_pty_master::close ()
     termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex);
   if (!NT_SUCCESS (status))
     debug_printf ("NtQueryObject: %y", status);
-  else if (obi.HandleCount == (get_pseudo_console () ? 2 : 1))
-			      /* Helper process has inherited one. */
+  else if (obi.HandleCount == 1)
     {
       termios_printf ("Closing last master of pty%d", get_minor ());
       /* Close Pseudo Console */
@@ -3167,14 +3166,14 @@ fhandler_pty_master::setup_pseudoconsole ()
     get_ttyp ()->attach_pcon_in_fork = true;
 
   SIZE_T bytesRequired;
-  InitializeProcThreadAttributeList (NULL, 1, 0, &bytesRequired);
+  InitializeProcThreadAttributeList (NULL, 2, 0, &bytesRequired);
   STARTUPINFOEXW si_helper;
   ZeroMemory (&si_helper, sizeof (si_helper));
   si_helper.StartupInfo.cb = sizeof (STARTUPINFOEXW);
   si_helper.lpAttributeList = (PPROC_THREAD_ATTRIBUTE_LIST)
     HeapAlloc (GetProcessHeap (), 0, bytesRequired);
   InitializeProcThreadAttributeList (si_helper.lpAttributeList,
-				     1, 0, &bytesRequired);
+				     2, 0, &bytesRequired);
   UpdateProcThreadAttribute (si_helper.lpAttributeList,
 			     0,
 			     PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
@@ -3186,6 +3185,14 @@ fhandler_pty_master::setup_pseudoconsole ()
   /* Create a pipe for receiving pseudo console handles */
   HANDLE hr, hw;
   CreatePipe (&hr, &hw, &sec_none, 0);
+  /* Inherit only handles which are needed by helper. */
+  HANDLE handles_to_inherit[] = {hello, goodbye, hw};
+  UpdateProcThreadAttribute (si_helper.lpAttributeList,
+			     0,
+			     PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
+			     handles_to_inherit,
+			     sizeof (handles_to_inherit),
+			     NULL, NULL);
   /* Create helper process */
   WCHAR cmd[MAX_PATH];
   path_conv helper ("/bin/cygwin-console-helper.exe");


                 reply	other threads:[~2020-01-14 16:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200114163040.127507.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).