Cygwin: pty: Call FreeConsole() only if attached to current pty.
- After commit 071b8e0cbd
, the problem
reported in https://cygwin.com/pipermail/cygwin/2020-May/244873.html
occurs. This is due to freeing console device accidentally rather
than pseudo console. This patch makes sure to call FreeConsole()
only if the process is attached to the pseudo console of the current
pty.
This commit is contained in:
parent
0f785536f3
commit
7659ff0f5a
|
@ -2284,6 +2284,7 @@ class fhandler_pty_slave: public fhandler_pty_common
|
|||
|
||||
bool try_reattach_pcon ();
|
||||
void restore_reattach_pcon ();
|
||||
inline void free_attached_console ();
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
|
|
|
@ -180,6 +180,16 @@ set_ishybrid_and_switch_to_pcon (HANDLE h)
|
|||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
fhandler_pty_slave::free_attached_console ()
|
||||
{
|
||||
if (freeconsole_on_close && get_minor () == pcon_attached_to)
|
||||
{
|
||||
FreeConsole ();
|
||||
pcon_attached_to = -1;
|
||||
}
|
||||
}
|
||||
|
||||
#define DEF_HOOK(name) static __typeof__ (name) *name##_Orig
|
||||
DEF_HOOK (WriteFile);
|
||||
DEF_HOOK (WriteConsoleA);
|
||||
|
@ -708,11 +718,7 @@ fhandler_pty_slave::~fhandler_pty_slave ()
|
|||
if (!get_ttyp ())
|
||||
{
|
||||
/* Why comes here? Who clears _tc? */
|
||||
if (freeconsole_on_close)
|
||||
{
|
||||
FreeConsole ();
|
||||
pcon_attached_to = -1;
|
||||
}
|
||||
free_attached_console ();
|
||||
return;
|
||||
}
|
||||
if (get_pseudo_console ())
|
||||
|
@ -739,11 +745,7 @@ fhandler_pty_slave::~fhandler_pty_slave ()
|
|||
if (used == 0)
|
||||
{
|
||||
init_console_handler (false);
|
||||
if (freeconsole_on_close)
|
||||
{
|
||||
FreeConsole ();
|
||||
pcon_attached_to = -1;
|
||||
}
|
||||
free_attached_console ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3006,11 +3008,7 @@ fhandler_pty_slave::fixup_after_exec ()
|
|||
if (used == 1 /* About to close this tty */)
|
||||
{
|
||||
init_console_handler (false);
|
||||
if (freeconsole_on_close)
|
||||
{
|
||||
FreeConsole ();
|
||||
pcon_attached_to = -1;
|
||||
}
|
||||
free_attached_console ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue