]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: pty: Fix master closing error regarding attach_mutex.
authorTakashi Yano <takashi.yano@nifty.ne.jp>
Fri, 8 Oct 2021 16:28:54 +0000 (01:28 +0900)
committerKen Brown <kbrown@cornell.edu>
Fri, 8 Oct 2021 17:27:50 +0000 (13:27 -0400)
- If two or more pty masters are opened in a process, closing master
  causes error when closing attach_mutex. This patch fixes the issue.

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-October/012418.html

winsup/cygwin/fhandler_tty.cc
winsup/cygwin/release/3.3.0

index 05fe5348af7e4d9d6fc739c73c776b66d8769c0a..823dabf730a82932de67d8d4d69bea746c209d17 100644 (file)
@@ -57,6 +57,7 @@ struct pipe_reply {
 };
 
 extern HANDLE attach_mutex; /* Defined in fhandler_console.cc */
+static LONG NO_COPY master_cnt = 0;
 
 inline static bool pcon_pid_alive (DWORD pid);
 
@@ -2041,7 +2042,8 @@ fhandler_pty_master::close ()
            }
          release_output_mutex ();
          master_fwd_thread->terminate_thread ();
-         CloseHandle (attach_mutex);
+         if (InterlockedDecrement (&master_cnt) == 0)
+           CloseHandle (attach_mutex);
        }
     }
 
@@ -2876,7 +2878,8 @@ fhandler_pty_master::setup ()
   if (!(pcon_mutex = CreateMutex (&sa, FALSE, buf)))
     goto err;
 
-  attach_mutex = CreateMutex (&sa, FALSE, NULL);
+  if (InterlockedIncrement (&master_cnt) == 1)
+    attach_mutex = CreateMutex (&sa, FALSE, NULL);
 
   /* Create master control pipe which allows the master to duplicate
      the pty pipe handles to processes which deserve it. */
index 2f7340ac5f19369875bd1400dd1709c9393752cf..2df81a4ae9e12f97fcf4a8edd409a1b54ea5a44c 100644 (file)
@@ -71,3 +71,6 @@ Bug Fixes
   in ps(1) output.
   Addresses: https://cygwin.com/pipermail/cygwin/2021-July/248998.html
              https://cygwin.com/pipermail/cygwin/2021-August/249124.html
+
+- Fix pty master closing error regarding attach_mutex.
+  Addresses: https://cygwin.com/pipermail/cygwin-developers/2021-October/012418.html
This page took 0.041371 seconds and 5 git commands to generate.