* [PATCH] Cygwin: pty: Fix master closing error regarding attach_mutex.
@ 2021-10-08 16:28 Takashi Yano
2021-10-08 17:30 ` Ken Brown
0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2021-10-08 16:28 UTC (permalink / raw)
To: cygwin-patches
- 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 | 7 +++++--
winsup/cygwin/release/3.3.0 | 3 +++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 05fe5348a..823dabf73 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -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. */
diff --git a/winsup/cygwin/release/3.3.0 b/winsup/cygwin/release/3.3.0
index 2f7340ac5..2df81a4ae 100644
--- a/winsup/cygwin/release/3.3.0
+++ b/winsup/cygwin/release/3.3.0
@@ -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
--
2.33.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Cygwin: pty: Fix master closing error regarding attach_mutex.
2021-10-08 16:28 [PATCH] Cygwin: pty: Fix master closing error regarding attach_mutex Takashi Yano
@ 2021-10-08 17:30 ` Ken Brown
0 siblings, 0 replies; 2+ messages in thread
From: Ken Brown @ 2021-10-08 17:30 UTC (permalink / raw)
To: cygwin-patches
On 10/8/2021 12:28 PM, Takashi Yano wrote:
> - 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 | 7 +++++--
> winsup/cygwin/release/3.3.0 | 3 +++
> 2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index 05fe5348a..823dabf73 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -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. */
> diff --git a/winsup/cygwin/release/3.3.0 b/winsup/cygwin/release/3.3.0
> index 2f7340ac5..2df81a4ae 100644
> --- a/winsup/cygwin/release/3.3.0
> +++ b/winsup/cygwin/release/3.3.0
> @@ -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
Pushed. Thanks.
Ken
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-08 17:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08 16:28 [PATCH] Cygwin: pty: Fix master closing error regarding attach_mutex Takashi Yano
2021-10-08 17:30 ` Ken Brown
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).