Skip to content

Commit

Permalink
Cygwin: console: Make the console accessible from other terminals.
Browse files Browse the repository at this point in the history
Previously, the console device could not be accessed from other terminals.
Due to this limitation, GNU screen and tmux cannot be opened in console.
With this patch, console device can be accessed from other TTYs, such as
other consoles or ptys. Thanks to this patch, screen and tmux get working
in console.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
  • Loading branch information
tyan0 committed Dec 22, 2022
1 parent 043b608 commit 3721a75
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 138 deletions.
24 changes: 22 additions & 2 deletions winsup/cygwin/devices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ exists_ntdev_silent (const device& dev)
return exists_ntdev (dev) ? -1 : false;
}

static BOOL CALLBACK
enum_cons_dev (HWND hw, LPARAM lp)
{
unsigned long *bitmask = (unsigned long *) lp;
HANDLE h = NULL;
fhandler_console::console_state *cs;
if ((cs = fhandler_console::open_shared_console (hw, h)))
{
*bitmask |= (1UL << cs->tty_min_state.getntty ());
UnmapViewOfFile ((void *) cs);
CloseHandle (h);
}
return TRUE;
}

static int
exists_console (const device& dev)
{
Expand All @@ -81,8 +96,13 @@ exists_console (const device& dev)
return cygheap && cygheap->ctty && cygheap->ctty->is_console ()
&& fhandler_console::exists ();
default:
/* Only show my own console device (for now?) */
return iscons_dev (myself->ctty) && myself->ctty == devn;
if (dev.get_minor () < MAX_CONS_DEV)
{
unsigned long bitmask = 0;
EnumWindows (enum_cons_dev, (LPARAM) &bitmask);
return bitmask & (1UL << dev.get_minor ());
}
return false;
}
}

Expand Down
24 changes: 22 additions & 2 deletions winsup/cygwin/devices.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ exists_ntdev_silent (const device& dev)
return exists_ntdev (dev) ? -1 : false;
}

static BOOL CALLBACK
enum_cons_dev (HWND hw, LPARAM lp)
{
unsigned long *bitmask = (unsigned long *) lp;
HANDLE h = NULL;
fhandler_console::console_state *cs;
if ((cs = fhandler_console::open_shared_console (hw, h)))
{
*bitmask |= (1UL << cs->tty_min_state.getntty ());
UnmapViewOfFile ((void *) cs);
CloseHandle (h);
}
return TRUE;
}

static int
exists_console (const device& dev)
{
Expand All @@ -77,8 +92,13 @@ exists_console (const device& dev)
return cygheap && cygheap->ctty && cygheap->ctty->is_console ()
&& fhandler_console::exists ();
default:
/* Only show my own console device (for now?) */
return iscons_dev (myself->ctty) && myself->ctty == devn;
if (dev.get_minor () < MAX_CONS_DEV)
{
unsigned long bitmask = 0;
EnumWindows (enum_cons_dev, (LPARAM) &bitmask);
return bitmask & (1UL << dev.get_minor ());
}
return false;
}
}

Expand Down
Loading

0 comments on commit 3721a75

Please sign in to comment.