Skip to content

Commit

Permalink
Cygwin: console: Fix for GNU screen/tmux in ConEmu
Browse files Browse the repository at this point in the history
If the master process of GNU screen or tmux is started in ConEmu
and ConEmu is closed, reattaching to the GNU screen/tmux in another
console will not work correctly. This is because the ConEmu master
process was already closed even though some console APIs are hooked
by ConEmuHk64.dll to communicate with ConEmu master process. With
this patch, to make them unhooked, DllMain() of ConEmuHk64.dll is
called with DLL_PROCESS_DETACH.

Fixes: 3721a75 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <[email protected]>
(cherry picked from commit ac7c0e23d85a638e6f930aa9a0582812e886a688)
  • Loading branch information
tyan0 committed Jul 8, 2024
1 parent cc9dcdb commit ce3889a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion winsup/cygwin/fhandler/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ details. */
#include "child_info.h"
#include "cygwait.h"
#include "winf.h"
#include "psapi.h"

/* Don't make this bigger than NT_MAX_PATH as long as the temporary buffer
is allocated using tmp_pathbuf!!! */
Expand Down Expand Up @@ -1970,7 +1971,23 @@ fhandler_console::close ()
if (!have_execed && !invisible_console
&& (!CTTY_IS_VALID (myself->ctty)
|| get_device () == (dev_t) myself->ctty))
free_console ();
{
/* ConEmu hack. Detach from ConEmu to unhook console APIs. */
HMODULE h = GetModuleHandle ("ConEmuHk64.dll");
if (h)
{
MODULEINFO mi;
if (GetModuleInformation (GetCurrentProcess (), h, &mi, sizeof (mi)))
{
BOOL (*DllMain)(HINSTANCE, DWORD, LPVOID) =
(BOOL (*)(HINSTANCE, DWORD, LPVOID)) mi.EntryPoint;
DllMain (h, DLL_PROCESS_DETACH, NULL);
}
}

/* Freeing console to detach the process from the console. */
free_console ();
}

release_output_mutex ();

Expand Down

0 comments on commit ce3889a

Please sign in to comment.