Skip to content

Commit

Permalink
Cygwin: console: Fix clean up conditions in close()
Browse files Browse the repository at this point in the history
Previously, the condition to clean up input/output mode was based
on wrong premise. This patch fixes that.

Fixes: 8ee8b0c ("Cygwin: console: Use GetCurrentProcessId() instead of myself->dwProcessId")
Signed-off-by: Takashi Yano <[email protected]>
  • Loading branch information
tyan0 committed Nov 8, 2024
1 parent 90031ff commit 30d2669
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions winsup/cygwin/fhandler/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1976,16 +1976,16 @@ fhandler_console::close ()

acquire_output_mutex (mutex_timeout);

if (shared_console_info[unit])
if (shared_console_info[unit] && !myself->cygstarted
&& (dev_t) myself->ctty == get_device ())
{
/* Restore console mode if this is the last closure. */
OBJECT_BASIC_INFORMATION obi;
NTSTATUS status;
status = NtQueryObject (get_handle (), ObjectBasicInformation,
&obi, sizeof obi, NULL);
if (NT_SUCCESS (status)
&& obi.HandleCount <= (myself->cygstarted ? 2 : 3)
&& (dev_t) myself->ctty == get_device ())
&& obi.HandleCount == (con.owner == GetCurrentProcessId () ? 2 : 3))
{
/* Cleaning-up console mode for cygwin apps. */
set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
Expand Down

0 comments on commit 30d2669

Please sign in to comment.