public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: console: Add workaround for ConEmu cygwin connector.
Date: Fri, 29 Jul 2022 00:13:55 +0900	[thread overview]
Message-ID: <20220728151355.1844-1-takashi.yano@nifty.ne.jp> (raw)

- ConEmu cygwin connector conflicts with cons_master_thread since
  it does not use read() to read console input. With this patch,
  cons_master_thread is disabled in ConEmu cygwin connector.
---
 winsup/cygwin/fhandler_console.cc | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index c20239d13..37262f638 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -1604,6 +1604,8 @@ fhandler_console::dup (fhandler_base *child, int flags)
   return 0;
 }
 
+static void hook_conemu_cygwin_connector();
+
 int
 fhandler_console::open (int flags, mode_t)
 {
@@ -1691,6 +1693,8 @@ fhandler_console::open (int flags, mode_t)
 
   if (myself->pid == con.owner)
     {
+      if (GetModuleHandle ("ConEmuHk64.dll"))
+	hook_conemu_cygwin_connector ();
       char name[MAX_PATH];
       shared_name (name, CONS_THREAD_SYNC, get_minor ());
       thread_sync_event = CreateEvent(NULL, FALSE, FALSE, name);
@@ -3982,6 +3986,7 @@ fhandler_console::set_console_mode_to_native ()
 DEF_HOOK (CreateProcessA);
 DEF_HOOK (CreateProcessW);
 DEF_HOOK (ContinueDebugEvent);
+DEF_HOOK (LoadLibraryA); /* Hooked for ConEmu cygwin connector */
 
 static BOOL WINAPI
 CreateProcessA_Hooked
@@ -4023,6 +4028,20 @@ ContinueDebugEvent_Hooked
   return ContinueDebugEvent_Orig (p, t, s);
 }
 
+/* Hooked for ConEmu cygwin connector */
+static HMODULE WINAPI
+LoadLibraryA_Hooked (LPCSTR m)
+{
+  const char *p;
+  if ((p = strrchr(m, '\\')))
+    p++;
+  else
+    p = m;
+  if (strcasecmp(p, "ConEmuHk64.dll") == 0)
+    fhandler_console::set_disable_master_thread (true);
+  return LoadLibraryA_Orig (m);
+}
+
 void
 fhandler_console::fixup_after_fork_exec (bool execing)
 {
@@ -4046,6 +4065,12 @@ fhandler_console::fixup_after_fork_exec (bool execing)
   DO_HOOK (NULL, ContinueDebugEvent);
 }
 
+static void
+hook_conemu_cygwin_connector()
+{
+  DO_HOOK (NULL, LoadLibraryA);
+}
+
 /* Ugly workaround to create invisible console required since Windows 7.
 
    First try to just attach to any console which may have started this
-- 
2.37.1


                 reply	other threads:[~2022-07-28 15:14 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=20220728151355.1844-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    /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).